elasticsearch bool query combine must with OR

后端 未结 6 791
小蘑菇
小蘑菇 2020-11-28 00:51

I am currently trying to migrate a solr-based application to elasticsearch.

I have this lucene query

(( 
    name:(+foo +bar) 
    OR info:(+foo +bar         


        
6条回答
  •  醉酒成梦
    2020-11-28 01:11

    This is how you can nest multiple bool queries in one outer bool query this using Kibana,

    • bool indicates we are using boolean
    • must is for AND
    • should is for OR
    GET my_inedx/my_type/_search
    {
      "query" : {
         "bool": {             //bool indicates we are using boolean operator
              "must" : [       //must is for **AND**
                   {
                     "match" : {
                           "description" : "some text"  
                       }
                   },
                   {
                      "match" :{
                            "type" : "some Type"
                       }
                   },
                   {
                      "bool" : {          //here its a nested boolean query
                            "should" : [  //should is for **OR**
                                   {
                                     "match" : {
                                         //ur query
                                    }
                                   },
                                   { 
                                      "match" : {} 
                                   }     
                                 ]
                            }
                   }
               ]
          }
      }
    }
    

    This is how you can nest a query in ES


    There are more types in "bool" like,

    1. Filter
    2. must_not

提交回复
热议问题