我正在尝试使用not
构建对bool
的elasticsearch查询,因为不建议使用not
。例如。匹配不属于foo@bar.com
的所有文档。
我使用elasticsearch-dsl尝试了这些(在此之后https://www.elastic.co/blog/lost-in-translation-boolean-operations-and-filters-in-the-bool-query):
{'query': {
'bool': {
'must_not': [{
'match': {
'author': 'foo@bar.com'
}
}]
}
}}
尽管存在
'author': 'foo@bar.com'
以外的文档,但没有返回结果。我也试过
{'query': {
'bool': {
'must_not': [{
'term': {
'author': 'foo@bar.com'
}
}]
}
}}
这将返回混合文档,其中一些文档带有
'author': 'foo@bar.com'
,而有些则没有。
最佳答案
原来这是5.0中的映射更改的问题(https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_50_mapping_changes.html)
以下查询按预期工作:
{'query': {
'bool': {
'must_not': [{
'term': {
'author.keyword': 'foo@bar.com'
}
}]
}
}}
关于elasticsearch - 使用bool而不是不使用 Elasticsearch 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45517315/