DMx
DMx

Reputation: 29

How to write this query in elasticsearch

I have SQL query:

WHERE A = 1 AND B = 2 AND C REGEXP (eee|fff|ggg)

How can I write this query in elasticsearch ?

Upvotes: 0

Views: 68

Answers (1)

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38502

Not tested but something like this QUERY-DSL you need for your case with filter and regexp,

GET /_search
{
  "size": 10, 
   "query": {
        "filter" : {
            "bool" : {
              "must" : [
                 { "term" : {"A" : 1}}, 
                 { "term" : {"B" : 2}} 
              ]
           }
         },
        "regexp": {
            "C": {
                "value": "eee|fff|ggg"
            }
        }
    }
}

OR

GET /_search
{
  "size": 10,
  "query": {
    "filter": {
      "bool": {
        "must": [
          {
            "term": {
              "A": 1
            }
          },
          {
            "term": {
              "B": 2
            }
          },
          {
            "regexp": {
              "C": {
                "value": "eee|fff|ggg"
              }
            }
          }
        ]
      }
    }
  }
} 

Upvotes: 1

Related Questions