#查看索引配置信息#
GET /test_index/_settings
#1.數(shù)據(jù)準(zhǔn)備#
PUT user_index
{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 3
},
"mappings": {
"properties": {
"name": {
"type": "text"
},
"address": {
"type": "text"
},
"age": {
"type": "integer"
},
"interests": {
"type": "text"
},
"birthday": {
"type": "date"
}
}
}
}
GET /user_index
#2.插入數(shù)據(jù)#
POST /user_index/_doc/1
{
"name":"lisi",
"address":"shandong",
"age":18,
"interests":"youyong shufa changge tiaowu",
"birthday":"2001-01-19"
}
POST /user_index/_doc/2
{
"name": "wangwu",
"address": "zhejiang",
"age": 22,
"interests": "youyong shufa",
"birthday": "1997-01-19"
}
POST /user_index/_doc/3
{
"name": "zhangsan",
"address": "zhejiang",
"age": 20,
"interests": "youyong shufa changge changpao",
"birthday": "1999-08-29"
}
POST /user_index/_doc/6
{
"name": "youyong",
"address": "zhejiang",
"age": 22,
"interests": "youyong shufa changge changpao",
"birthday": "1999-08-29"
}
#精確查詢#
GET /user_index/_search?q=name:youyong
GET /user_index/_search?q=name:youyong&sort=age:desc
#term查詢和terms查詢:term query去倒排索引中找到確切的term,不知道分詞器的存在,適合keyword,date,numetic,是包含(contains操作),不是等值(equals)判斷#
GET /user_index/_doc/_search
{
"query":{
"term":{
"interests":"changpao"
}
}
}
GET /user_index/_doc/_search
{
"query":{
"terms":{
"interests":["youyong","shufa"]
}
}
}
#查詢控制返回的數(shù)量#
GET /user_index/_search
{
"from": 0,
"size": 2,
"query": {
"terms": {
"interests": [
"shufa",
"youyong"
]
}
}
}
#返回版本號(hào),版本號(hào)是啥???
GET /user_index/_search
{
"version": true,
"from": 0,
"size": 2,
"query": {
"terms": {
"interests": [
"shufa",
"youyong"
]
}
}
}
#match查詢,知道分詞器的存在,對(duì)filed會(huì)進(jìn)行分詞操作,再查詢
#單字段查詢 match
GET user_index/_search
{
"query": {
"match": {
"age": 20
}
}
}
GET user_index/_search
{
"query": {
"match": {
"interests": "changge"
}
}
}
#指定多字段查詢 multi_match
GET user_index/_search
{
"query": {
"multi_match": {
"query": "youyong",
"fields": ["interests","name"]
}
}
}
#短語匹配查詢
GET user_index/_search
{
"query": {
"match_phrase": {
"interests": "shufa changge"
}
}
}
#查詢?nèi)?GET /user_index/_search/
{
"query": {
"match_all": {}
}
}
#指定返回的字段
GET /user_index/_search
{
"_source": ["name","age"],
"query":{
"match": {
"interests": "changge"
}
}
}
#指定需要的字段,去除不要的字段,可使用通配符
GET /user_index/_search
{
"query": {
"match_all": {}
},
"_source": {
"includes": "addr*",
"excludes": ["name","dir*"]
}
}
#排序
#前綴匹配查詢,并使用sort排序:desc:降序,asc:升序
GET /user_index/_search
{
"query": {
"match_phrase_prefix": {
"interests": "you"
}
},
"sort": [
{
"age": {
"order": "desc"
}
}
]
}
# range范圍查詢,參數(shù) from,to,include_lower是否包含范圍左邊界,include_upper是否包含范圍右邊界,boost
GET /user_index/_search
{
"query": {
"range": {
"birthday": {
"gte": "1990-10-10",
"lte": "2000-05-01"
}
}
}
}
#wildcard查詢,允許通配符 * 和?來查詢; * 代表0個(gè)或多個(gè)字符, ? 代表任意一個(gè)字符
GET /user_index/_search
{
"query": {
"wildcard": {
"name": {
"value": "wang*"
}
}
}
}
# fuzzy 模糊查詢,與term查詢的模糊等價(jià),是包含(contains)操作,不是等值(equals)操作,不知道分詞器的存
GET /user_index/_search
{
"query": {
"fuzzy": {
"interests": "shuf"
}
}
}
# 刪除單個(gè):
DELETE /index
curl -XDELETE http://192.169.1.666:9200/index
#你也可以這樣刪除多個(gè)索引:
DELETE /index_one,index_two
curl -XDELETE http://192.169.1.666:9200/index_one,index_two
DELETE /index_*
curl -XDELETE http://192.169.1.666:9200/index_*
ES | ES 查詢命令
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 一:_cat系列 _cat系列提供了一系列查詢elasticsearch集群狀態(tài)的接口。你可以通過執(zhí)行 curl ...
- curl -XPUT http://127.0.0.1:9200/_all/_settings -H 'Cont...
- 項(xiàng)目中的es查詢需求需要查詢多種多樣的文本,并且根據(jù)一系列的條件進(jìn)行過濾。而es如何去構(gòu)建復(fù)雜的多條件查詢呢? 1...
- 內(nèi)容簡介 1.spring整合es2.普通查詢的使用方法3.聚合查詢的使用方法4.普通查詢與聚合查詢的使用區(qū)別 s...
- 16宿命:用概率思維提高你的勝算 以前的我是風(fēng)險(xiǎn)厭惡者,不喜歡去冒險(xiǎn),但是人生放棄了冒險(xiǎn),也就放棄了無數(shù)的可能。 ...