尽管您的工作可行,但更干净的解决方案是使用过滤查询。
http://www.elasticsearch.org/guide/reference/query-dsl/filtered-
query/
允许您使用原始查询+一些任意过滤器(依次可以是复杂的布尔值/嵌套过滤器等)
{ query: { "filtered" : {"query": {"query_string": {"query": "%s" % q}},"filter":{"ids":{"values":list(ids)}}, } }, "facets": { "destination": { "terms": {"field": "destination.en"} }, "hotel_class": { "terms": {"field": "hotel_class"} }, "hotel_type": { "terms": {"field": "hotel_type"} } } }基本原理如下:
- 在构面之前应用任何查询。
- 在构面之后应用所有过滤器。
因此,如果您希望通过某些过滤器过滤方面,则必须在QUERY中包括该过滤器。



