我如何创建Elasticsearch curl查询以获取不为null且不为空的字段值(“”),

这是mysql查询:

select field1 from mytable where field1!=null and field1!="";

最佳答案

空值和空字符串都不会索引任何值,在这种情况下,您可以使用exists过滤器

curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1'  -d '
{
   "query" : {
      "constant_score" : {
         "filter" : {
            "exists" : {
               "field" : "myfield"
            }
         }
      }
   }
}
'

或结合(例如)在title字段上进行全文搜索:
curl -XGET 'http://127.0.0.1:9200/test/test/_search?pretty=1'  -d '
{
   "query" : {
      "filtered" : {
         "filter" : {
            "exists" : {
               "field" : "myfield"
            }
         },
         "query" : {
            "match" : {
               "title" : "search keywords"
            }
         }
      }
   }
}
'

关于elasticsearch - 为不为null和不为空的Elasticsearch curl查询创建(“”),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14745210/

10-11 04:21