如何在弹性搜索中执行内滤镜 [英] How to perform inner filter in elastic search

查看:125
本文介绍了如何在弹性搜索中执行内滤镜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 (item_id == 1&& name = =约翰)|| (product_id == 234&& vendor!=youtube)&& (日期> =2014-11-01&  =2014-11-18)

我指的是这个链接:

  http://www.elasticsearch.org/guide/en/ elasticsearch /客户/ Java的API /电流/ search.html。 

然后对searchQueryBuilder执行后置过滤操作。但是当我们使用后置过滤器时,排序不是woks。



我已经提出了有关帖子过滤器+排序不正常的问题。

  http://stackoverflow.com/questions/26986756/filter-sorting-not-working-in-elastic-search 

这里有一个关于使用过滤器的信息,只有当聚合发生时。



需要知道如何实现Nester过滤器+排序在一起。



文档链接将有很大的帮助。

解决方案

要在过滤器中执行所有操作:

  curl -XGEThttp:// localhost:9200 / hubware3 / message / _search?pretty-d'{
filter:{
and:[{
bool:{
should:[{
bool:{
must:[
{term:{item_id 1}},
{term:{name:John}}
]
}},
{bool:{
must:{
term:{product_id:234}
},
must_not:{
term:{vendor :youtube}
}
}
}
]
}},
{range:{date:{gte :2014-11-01,lte:2014-11-18}}}
]
}
}'

bool必须可变的。


I need to do a nested filter stuff in elastic search.

(item_id == 1 && name == "John") || (product_id == 234 && vendor !="youtube") && (date >="2014-11-01" && date <="2014-11-18")

I refer this link:

http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.html.

And performed the post filter operation towards the searchQueryBuilder.but sorting is not woks when we use post filter.

I have already rise question about post filter + sort not working.

http://stackoverflow.com/questions/26986756/filter-sorting-not-working-in-elastic-search

There I got a info about using the post filter only when the aggregation occurred.

Need to know how can I achieve the nester filter + sorting together.

Documentation link will be much help full.

解决方案

To do everything in a filter:

curl -XGET "http://localhost:9200/hubware3/message/_search?pretty" -d' {
  "filter" : {
    "and" : [{
        "bool" : {
          "should" :[ {
            "bool" : {
              "must" : [
                {"term" : { "item_id" : "1" }},
                {"term" : { "name" : "John" }}
               ]
             }},
            {"bool" : {
              "must" : {
                "term" : { "product_id" : "234" }
             },
             "must_not" : {
                "term" : { "vendor" : "youtube" }
              }
            }
           }
          ]
        }},
        {"range" : {"date " : { "gte" : "2014-11-01","lte" : "2014-11-18"}}}
     ]
  }
}'

and and bool must are interchangeable.

这篇关于如何在弹性搜索中执行内滤镜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆