How to query elasticsearch based on response


(adhikar) #1

Hi, Im trying to query elasticsearch to do the following :

Data going into Elastic

Order Number	Product Name
order1   	    Chicken    
order2   	    Banana
order3	        Chicken   
order1	        Cucumber   
order2   	    Chicken
order3     	    Apples
order1   	    Flour
order2   	    Rice
order3    	    Nuts

This is the Query im using to get a Product Name

{
    "query" : {
        "match" : {
        "ProductName" : "Chicken"
}

Result : All orders that contain Chicken

    Order Number	Product Name
    order1   	    Chicken          
    order3	        Chicken
    order2       	Chicken

What I would like to achieve:
If the above orders have Chicken in it then give me all the other Products that was also purchased with Chicken.

Order Number   	Product Name
order1	        Cucumber
order2        	Banana
order3        	Apples
order1        	Flour
order2        	Rice
order3        	Nuts

How do i go about constructing a query to do this ? please help i am very new to elasticsearch.

  • Do i require to Run the first query get all orders that contain Chicken then extract the order numbers and run another query ?

(Mark Walkom) #2

You need to do two queries, and issue the second one from your client. You cannot chain queries like this natively.


(system) #3

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