ElasticSearch basic grammar api

查询 所有索引
GET /_cat/indices


批查询 api mget
GET /_mget
{
"docs":[
{
"_index":"mc_prescription_rec",
"_type":"prescription",
"_id":"115654_2036"

},
{
"_index":"mc_prescription_rec",
"_type":"prescription",
"_id":"115654_2163"

},
{
"_index":"mc_prescription_rec",
"_type":"prescription",
"_id":"115654_2058"

}
]
}

Note: mget url request if there are requests index and body behind the type which you can not write index and type

E.g:

GET /mc_prescription_rec/prescription/_mget
{
"docs":[
{

"_id":"115654_2036"

},
{

"_id":"115654_2163"

},
{

"_id":"115654_2058"

}
]
}


查询 所有
GET /mc_prescription_rec/prescription/_search
{
"query":{
"match_all": {}
}
}


Url specified field of inquiry:

GET mc_prescription_rec/prescription/_search?q=paid:1



GET /mc_prescription_rec/prescription/_search
{
"query":{
"match": {
"positive_tags": "预防"
}
}

}

Find a range

GET /mc_prescription_rec/prescription/_search
{
"query":{
"range": {
"prescription_id": {
"gte": 2000,
"lte": 2100
}
}
}

}


多条件的 复合 查询
GET /mc_prescription_rec/prescription/_search
{
"query":{
"bool": {
"must": [
{ "match": {
"status": "0"
}}
],
"should": [
{"match": {
"paid": "1"
}
},
{"match": {
"positive_tags": "健身"
}


}
],
"minimum_should_match": 1

}
}

}

 

GET /mc_prescription_rec/prescription/_search
{
"query":{
"bool": {
"must": [
{"match": {
"prescription_id": "2129"
}

},
{"match": {
"app_id": "313304"
}

}
]

}
}

}

Note: bool are some of the conditions inside, must be hiding foot, should be met as long as the condition is minimum_should_match ture, filter just filter not scored


Show only the specified result (_source)

GET /mc_prescription_rec/prescription/_search
{
"query": {
"match_all": {}
},
"_source": ["prescription_id","app_id"]
}


Post_filter and query the difference, not the differences in syntax, only that the filter does not score, so much faster than the query filter, filter and query can coexist.

GET /mc_prescription_rec/prescription/_search
{
"post_filter": {
"match_all": {}
},
"_source": ["prescription_id","app_id"]
}

 


查询非分页
GET /mc_prescription_rec/prescription/_search
{
"query":{
"match_all": {}
},
"from":1076,
"size":2

}


NOTE: deep paging problem, efficiency is very low, Energizer avoid deep paging.

  Note 2: Dark Page: If you want to check out page 100, page 100 data (9900--10000), if it is to five nodes query, the query would first 9900-10000 pieces of data at each node, and then aggregated to the coordinates of points, then sorted out 9900-10000 bar, this is very much resources.

查询结果范例:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 135,
"max_score": 1,
"hits": [
{
"_index": "mc_prescription_rec",
"_type": "prescription",
"_id": "313304_2169",
"_score": 1,
"_source": {
"app_id": 313304,
"prescription_id": 2169,
"status": 0,
"rcmd": 1,
"novice": 0,
"paid": 1,
"positive_tags": [
"预防心血管疾病"
],
"negative_tags": [],
"category": "",
"timestamp": 1573627618183
}
},
{
"_index": "mc_prescription_rec",
"_type": "prescription",
"_id": "316401_2165",
"_score": 1,
"_source": {
"app_id": 316401,
"prescription_id": 2165,
"status": 0,
"rcmd": 1,
"novice": 0,
"paid": 1,
"positive_tags": [
"减肥"
],
"negative_tags": [],
"category": "",
"timestamp": 1573627617081
}
}]
}}


https://www.cnblogs.com/cxygg/p/9471372.html

Guess you like

Origin www.cnblogs.com/yazhong-java/p/12636888.html