我需要用某种条件逻辑(我认为)过滤掉文档,但我无法实现这个工作。Elasticsearch条件筛选器
我的文件是这样的: {type: 'A'} {type: 'B', foo: ['bar']} {type: 'B', foo: []}
现在我需要过滤掉type
“B”,其中foo
是空的所有文件。 伪代码查询将是: if(type == 'B' && foo == []) { // filter out this document }
我的主查询看起来是这样的: query: { filtered: { query: { bool: { must: { match_all: [] } } }, filter: { bool:{ must_not: { term: {'_hidden': true} } } } } }
Elasticsearch版本是1.5.0
Elasticsearch不存储空字段。我想你说的是一个不存在的领域,对吧?你可以在must_not中使用exists过滤器吗? https://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-exists-filter.html 你尝试过吗? –
Hi @WaldemarNeto。是的,我确实尝试使用“存在”和/或“丢失”过滤器。 这对于'B'类型的所有文件都有效。但它也会过滤所有类型为'A'的文档,因为从来没有“property”foo。 –
为了理解,如果输入==“A”foo无关紧要,对吧?如果type ==“B”foo需要为空? –