PUT /employee/_doc/1 { "address": { "country": "china", "province": "jiangsu", "city": "nanjing" }, "name": "tom", "age": 30, "join_date": "2016-01-01" } PUT /employee/_doc/2 { "address": { "country": "china", "province": "shanxi", "city": "xian" }, "name": "marry", "age": 35, "join_date": "2015-01-01" }
搜索请求:年龄必须大于等于30,同时join_date必须是2016-01-01缓存
GET /employee/_search { "query": { "bool": { "must": [ { "match": { "join_date": "2016-01-01" } } ], "filter": { "range": { "age": { "gte": 30 } } } } } } { "took" : 141, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "employee", "_type" : "_doc", "_id" : "1", "_score" : 1.0, "_source" : { "address" : { "country" : "china", "province" : "jiangsu", "city" : "nanjing" }, "name" : "tom", "age" : 30, "join_date" : "2016-01-01" } } ] } }
通常来讲,若是是在进行搜索,须要将最匹配搜索条件的数据先返回,那么用query。若是只是要根据一些条件筛选出一部分数据,不关注其排序,那么用filter。性能