ES DSL查询总结
DSL查询有两种
1 match
GET cargo_index-202111/_search { "query": { "match": { "cargoId": 29951002600481 } } }
特点:不支持多字段查询,比如上面的查询只能根据cargoId进行查询
2 bool查询,可以多字段嵌套
GET /cargo_index-202110/_search?pretty { "query": { "bool": { "must": [ {"term": { "cargoId": { "value": 10141155359512 } }}, {"term": { "dispatchStatus": { "value": 1 } }},{"range": { "endLoadTime": { "gte": 20, "lte": 1634659200000 } }} ] } } }
除了must还有很多,should,must_not等
{ "bool" : { "must" : { "term" : { "user" : "kimchy" } }, "filter": { "term" : { "tag" : "tech" } }, "must_not" : { "range" : { "age" : { "from" : 10, "to" : 20 } } }, "should" : [ { "term" : { "tag" : "wow" } }, { "term" : { "tag" : "elasticsearch" } } ], "minimum_should_match" : 1, "boost" : 1.0 } }