# Quey elasticsearch jason

**URL:** <https://discuss.elastic.co/t/quey-elasticsearch-jason/72479>\
**Category:** Elasticsearch\
**Created:** [January 23, 2017, 12:29pm UTC](https://discuss.elastic.co/t/quey-elasticsearch-jason/72479 "2017-01-23T12:29:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adhikz](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@adhikz](https://discuss.elastic.co/u/adhikz)\
**Post date:** [January 23, 2017, 12:29pm UTC](https://discuss.elastic.co/t/quey-elasticsearch-jason/72479/1 "2017-01-23T12:29:38Z")

</div>

Hi, I am trying to query elasticsearch in order to find out what products were bought with a certain product.

**My data going into logstash from a flat file.**

```
 OrderNumber ProductName
    order1 Chicken    
    order2 Banana
    order3 Chicken   
    order1 Cucumber   
    order2 Chicken 
    order3 Apples
    order1 Flour
    order2 Rice
    order3 Nuts

```

As you can see above i have an **Product Name** of **Chicken** which occurs in different **Order Numbers**.

```
 OrderNumber ProductName
    order1 Chicken          
    order3 Chicken
    order2 Chicken

```

This is what i would like to achieve :

**Step 1 : Lookup all order Numbers that contain chicken**

```
 OrderNumber ProductName
    order1 Chicken          
    order3 Chicken
    order2 Chicken

```

**Step 2 : if the above orders have chicken in it give me all the other products that was also purchased with it**

Result :

```
     OrderNumber ProductName
     order1 Cucumber
     order2 Banana
     order3 Apples
     order1 Flour
     order2 Rice
     order3 Nuts

```

This is what i have tried so far for **Step1** :

**Query**

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

```

**Result**

```
  "hits" : {
    "total" : 3,
    "max_score" : 11.378191,
    "hits" : [ {
      "_index" : "hello",
      "_type" : "logs",
      "_id" : "AVmxaChupyZuCjD89xPX",
      "_score" : 11.378191,
      "_source" : {
        "message" : "order1\Chicken\r",
        "path" : "C:\\utils\\Elk\\logstash\\bin\\product.log",
        "OrderNumber" : "order1",
        "ProductName" : "Chicken\r"
      }}, {
      "_index" : "hello",
      "_type" : "logs",
      "_id" : "AVmxaChupyZuCjD89xPX",
      "_score" : 11.378191,
      "_source" : {
        "message" : "order3\Chicken\r",
        "path" : "C:\\utils\\Elk\\logstash\\bin\\product.log",
        "OrderNumber" : "order3",
        "ProductName" : "Chicken\r"
      }
   }, {
      "_index" : "hello",
      "_type" : "logs",
      "_id" : "AVmxaChupyZuCjD89xPX",
      "_score" : 11.378191,
      "_source" : {
        "message" : "order2\Chicken\r",
        "path" : "C:\\utils\\Elk\\logstash\\bin\\product.log",
        "OrderNumber" : "order2",
        "ProductName" : "Chicken\r"
      }

```

I'm very confused as to how to go about completing **step 2** as I am very new to Elasticsearch, please help ?

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 20, 2017, 12:29pm UTC](https://discuss.elastic.co/t/quey-elasticsearch-jason/72479/2 "2017-02-20T12:29:44Z")

</div>

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