本文介绍了创建弹性搜索卷曲查询不为空并且不为空(“”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何创建Elasticsearch卷曲查询以获取不为空的字段值,而不是空(),



这是mysql查询: p>

 从mytable中选择field1,其中field1!= null和field1!=; 


解决方案

空值和空字符串都会导致no值被索引,在这种情况下,您可以使用存在过滤器

 卷曲-XGET'http://127.0.0.1:9200/test/test/_search?pretty=1'-d'
{
查询:{
constant_score:{
filter:{
exists:{
field:myfield
}
}
}
}
}
'

或结合(例如)全文搜索标题字段:

  curl -XGET'http://127.0 .0.1:9200 / test / test / _search?pretty = 1'-d'
{
query:{
filtered:{
filter
存在:{
field:myfield
}
},
查询:{
match:{
title:search keywords
}
}
}
}
}
'
/ pre>

How can i create Elasticsearch curl query to get the field value which are not null and not empty(""),

Here is the mysql query:

select field1 from mytable where field1!=null and field1!="";
解决方案

A null value and an empty string both result in no value being indexed, in which case you can use the exists filter

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

Or in combination with (eg) a full text search on the title field:

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"
            }
         }
      }
   }
}
'

这篇关于创建弹性搜索卷曲查询不为空并且不为空(“”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:49
查看更多