2016-10-21 22 views

回答

1

弹性搜索查询看起来像这样

POST http://localhost:9200/<index>/<indextype>/_search 
{ 
    "query": { 
    "filtered": { 
     "filter": { 
     "term": { 
      "description": "" 
     } 
     } 
    } 
    } 
} 

不过它不工作,检查你的映射应该是这样的。

PUT http://localhost:9200/<index>/<indextype>/_mapping 
{ 
    "products": { 
    "properties": { 
     "description": { 
     "type": "string", 
     "index": "not_analyzed" 
     } 
    } 
    } 
} 

如果你想要结果与描述!='',然后使用下面的查询。

Missing Filter在Bool Filter的Must-Not部分中。它只会返回字段存在的文档,并且如果将“null_value”属性设置为true,则显式值不为null。

{ 
    "query": { 
    "filtered": { 
     "filter": { 
     "bool":{ 
      "must":{}, 
      "should":{}, 
      "must_not":{ 
      "missing":{ 
       "field":"description", 
       "existence":true, 
       "null_value":true 
       } 
      } 
     } 
     } 
    } 
    } 
} 
+0

感谢vinod,索引必须是“not_analyzed”?如果我想要描述!=''的结果,那么在elasticsearch中应该查询什么? – Rakesh

+0

我已经为您更新了我的答案。请检查。 –

+0

已检查Thans vinod – Rakesh