简体   繁体   中英

Search on multiple terms with Elastic Search

I'm new to ES and want to setup a query to search on multiple terms.

My SQL looks like:

"SELECT field4 FROM tablename WHERE (field1 = 'A' OR field1 = 'AA') AND (field2 = 'B' OR fields2 = 'BB') AND (field3 = 'C' OR field3 = 'CC')"

In ES I'm trying

{
"query": {
"bool": {
  "must": [
    {
      "term": {
        "field1": {"A","AA"}
      }
    },
    {
      "term": {
        "field2": {"B","BB"}
      }
    },
    {
    "term": {
      "field3": {"C","CC"}
    }
   }
  }
 }
}

What you most likely want is a terms query. You can see the documentation for it here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html

An example from that site is:

{
    "terms" : { "user" : ["kimchy", "elasticsearch"]}
}

Also, your query right now isn't valid json, you'll need to correct it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM