第
filter一个请求中的顶级元素在Elasticsearch中具有非常特殊的功能。它用于过滤搜索结果而不会影响构面。为了避免干扰方面,此过滤器在结果收集过程中而不是在搜索过程中应用,这会导致其性能下降。采用顶级
filter无需方面做很少的意义,因为
filtered与
constant_score查询通常提供更好的性能。如果
filtered查询的冗长
match_all困扰您,您可以将第二个请求重写为等效
constant_score查询:
{ "query": { "constant_score": { "filter": { "term": { "id": "123456" } } } }}


