当字段未定义或从对象丢失时从elasticsearch获取数据

我试图从弹性search中获取数据,通过查询指示对象是否已被处理的字段。 让我们把它叫做'isHandled'。

有一些没有这个字段索引的对象。 有没有办法得到“isHandled”只是不是“真”(假或甚至失踪)的数据?

谢谢

您可以使用exists查询来实现。 此查询将返回所有isHandled为false或不存在的文档。

 { "query": { "bool": { "should": [ { "term": { "isHandled": "false" } }, { "bool": { "must_not": { "exists": { "field": "isHandled" } } } } ] } } }