elastica - Elasticsearch bool filter with AND operator -


  1. i trying write query match multiple names, below query fine doesn't exact match e.g gives results name 'x a' or 'b y' want name exact or exact b.can tell me m doing wrong.
  2. also possible match multiple fields name=a or surname=a or name=b or surname=b

     {     "filter": {                 "bool": {                   "should": [                     {                       "term": {                         "name": "a"                       }                     },{                       "term": {                         "name": "b"                       }                     }                   ]                 }               },"sort": [                 {                   "pub": {                     "rank": "desc"                   }                 }               ]             } 

in boolean query, must means queries must evaluate true (so logical and), , should means @ least 1 must evaluate true (so logical or).

  1. to have exact match on name, need use keyword analyzer. stop names being tokenized on whitespace, "william riker" indexed (keyword analyzer) ["william riker"] or (default analyzer) ["william", "riker"]. in default case, match term query of either "william" or "riker". in keyword case match full name.

  2. to want, "name=a or surname=a or name=b or surname=b" make 4 should clauses.

     {          "bool":{             "should":[                {                   "term":{                      "name":"a"                 }              },              {                   "term":{                      "name":"b"                 }              },              {                   "term":{                      "surname":"a"                 }              },              {                   "term":{                      "surname":"b"                 }              }           ]        }     } 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -