elasticsearch must and should combined query

{"query": {
   "bool": {
     "should": [
       {"bool": {
         "must": [
           {}
         ]
       }
       },
       {"bool": {
         "must": [
           {}
         ]
       }}
     ]
   }
  }
}

 

bool filter

bool filtering can be used to combine the boolean logic of query results of multiple filter conditions. It includes the following operators:

  • must :: Exact match of multiple query conditions, equivalent to and.
  • must_not :: Inverse matching of multiple query conditions, equivalent to not.
  • should :: At least one query condition matches, equivalent to or.

These parameters can inherit a filter condition or an array of filter conditions respectively:


    "bool": { 
        "must":     { "term": { "folder": "inbox" }}, 
        "must_not": { "term": { "tag":    "spam"  }}, 
        "should": [ 
                    { "term": { "starred": true   }}, 
                    { "term": { "unread":  true   }} 
        ] 
    } 
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324972243&siteId=291194637