Help to convert SQL to ElasticSearch


(Irfan Hodzic) #1

Hey guys,

can somone help me to convert this sql query to elasticsearch query:

SELECT id, supplier FROM s_articles WHERE supplier NOT IN (1,2) OR id IN (1,2,3,4,5,6)


(Mark Walkom) #2

What have you tried so far?


(Irfan Hodzic) #3

I have tried to use should => must_not and should, but its not working.
Everything i try its not working..

Last query i have tried:

{
	"query": {
			"bool":{
				
				"should":{
					"bool":{
						"must_not":[
							{"term":{"supplier":1}},
							{"term":{"supplier":2}}
						],
						"should":[
							{"term":{"id":1}},
							{"term":{"id":2}},
							{"term":{"id":3}},
							{"term":{"id":4}},
							{"term":{"id":5}},
							{"term":{"id":6}}
						]
					}
				}
			}
		}
		
}

(Irfan Hodzic) #4

I have found the solution, thanks


(Mark Walkom) #5

Can you share it, it might help someone in the future :slight_smile:


(Irfan Hodzic) #6

Ofcourse, this is an solution.

{
	"query" : {
		"bool":{
			"should":[
					{
						"bool":{
							"must_not":[
								{"term":{"supplier":1}},
								{"term":{"supplier":2}}
							]
						}
					},
					{
						"bool":{
							"should":[
								{"term":{"id":1}},
								{"term":{"id":2}},
								{"term":{"id":3}},
								{"term":{"id":4}},
								{"term":{"id":5}},
								{"term":{"id":6}}
							]
						}
					}
			]
		}
	}
}

(system) #7

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