Or like in and


(Rishi) #1

Need to convert this query in ElasticSearch

WHERE (colD like 'abc%' OR colC like '%abc%') AND (colA IN ('a','b') OR colB IN ('a','b'))


(David Pilato) #2

What did you try so far?
Which part can’t you convert?

Have a look first at bool query.


(Rishi) #3
{
  "query": {
    "bool": {
      "must": [
        {
          "dis_max" : {
				"queries" : [
					{
						"wildcard" : { "colD" : "hil*" }
						},
						{
						"wildcard" : { "colC" : "hil*" }
						}
						
				]
			}
        },
        {
						"match" : { "colA" : "10216" }
						}
      ],
      "minimum_should_match": 1
    }
  }
}

(David Pilato) #4

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

I edited your post.

The sample query you pasted does not really look like to the one you asked for.

Was:

WHERE (colD like 'abc%' OR colC like '%abc%') AND (colA IN ('a','b') OR colB IN ('a','b'))

And you wrote something with hil* and colA=10216.

Let me give you some advices:

  • Don't use wildcards
  • Use the bool query. or clauses can be translated as should clauses. and clauses can be translated as must clauses.
  • You can use bool queries inside bool queries. Here I'd write something like (not tested):
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "wildcard": { "colD": "'abc%" } 
              },{
                "wildcard": { "colC": "'%abc%" } 
              }
            ]
          }
        }, {
          "bool": {
            "should": [
              {
                 // colA IN ('a','b')
              },{
                 // colB IN ('a','b')
              }
            ]
          }
        }
      ]
    }
  }
}

If you need more help, please provide a full recreation script as described in

It will help to better understand what you are doing.
Please, try to keep the example as simple as possible.


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.