[英]Elasticsearch exists filter how to make an empty string as null value?
I tried to index a name field to elasticsearch, the name maybe is a string or a empty string( ""
), I want to search all name which contain the empty value, so I use the exists
filter, but for exists
filter, the empty value is not a null value. 我试图将一个名称字段索引到elasticsearch,该名称可能是字符串或空字符串(
""
),我想搜索包含空值的所有名称,因此我使用了exists
过滤器,但对于exists
过滤器,空值不是空值。
https://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-exists-filter.html https://www.elastic.co/guide/zh-CN/elasticsearch/reference/1.4/query-dsl-exists-filter.html
query dsl: 查询dsl:
{ "filter" : {
"exists" : { "field" : "name" }
}
}
How to make the empty string as a null value for elasticsearch exist
filter? 如何使空字符串作为Elasticsearch
exist
过滤器的空值? Anyone has good idea? 有人有好主意吗?
The term filter should do the job: 术语过滤器可以完成以下任务:
{
"term": {
"name": ""
}
}
Just tried it with some of my data and got results, but might depend if your fields are "not-analyzed" (like mine) or not. 只是尝试使用我的一些数据并获得了结果,但可能取决于您的字段是否被“未分析”(例如我的)。
Update: Just found this similar question which has a much more detailed answer: Find documents with empty string value on elasticsearch 更新:刚刚发现了一个类似的问题,它有更详细的答案: 在elasticsearch上查找具有空字符串值的文档
You can try searching by using a script
filter instead in order to test the length of the string 您可以尝试使用
script
过滤器进行搜索,以测试字符串的长度
{
"query": {
"script": {
"script": "doc.name.value?.size() == 0"
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.