作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有2种文件:
"doc1":{
"dummy_attribute":"HI",
...
"important_attribute":{}
}
"doc2":{
"dummy_attribute":"HI",
...
}
如果我这样搜索:
GET myindex/_search
{
"query": {
"bool": {
"must_not": [{
"exists": {
"field": "important_attribute"
}
}]
}
}
}
它给我两个文件。
最佳答案
不幸的是,由于ES treats a non-existent value the same way as an empty-ish value(null
,""
,[]
或{}
),这是不可能的。
您可以使用脚本字段快速检查文档是否包含空字典,但是在过滤时不能使用此上下文:
GET myindex/_search
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "important_attribute"
}
}
]
}
},
"script_fields": {
"has_empty_dict": {
"script": {
"source": "params._source.containsKey('important_attribute') && params._source.important_attribute.size() == 0"
}
}
}
}
关于elasticsearch - 当字段不存在与字段存在但为null({})时,是否有办法区分Elasticsearch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64233627/
我是一名优秀的程序员,十分优秀!