# Elasticsearch jason query for recommendations

**URL:** <https://discuss.elastic.co/t/elasticsearch-jason-query-for-recommendations/72161>\
**Category:** Elasticsearch\
**Created:** [January 19, 2017, 11:40am UTC](https://discuss.elastic.co/t/elasticsearch-jason-query-for-recommendations/72161 "2017-01-19T11:40:31Z")\
**Posts on this page:** 6\
**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 19, 2017, 11:40am UTC](https://discuss.elastic.co/t/elasticsearch-jason-query-for-recommendations/72161/1 "2017-01-19T11:40:31Z")

</div>

Hi, I am currently trying to run an aggregation query to elasticsearch index to do recommendations.

**Data that im pushing to elasticsearch using logstash**

```
OrderNumber ProductName
o12345 Chicken         
o55631 Peanuts   
o12345 Apples
o98356 Avocado
o12345 Oranges
o31498 Peach
o12345 Grapes

```

As you can see above Order Number **o12345** is Unique which contains all products that was purchased for that order.

After the data is passed into Elasticsearch i get the following formatted output :

```
"_index" : "hello",
      "_type" : "logs",
      "_id" : "AVmxZxg-pyZuCjD89WOe",
      "_score" : 1.0,
      "_source" : {
        "message" : "o12345\Chicken\r",
        "@version" : "1",
        "@timestamp" : "2017-01-18T11:47:20.518Z",
        "path" : "C:\\Elk\\logstash\\bin\\mylog.log",
        "host" : "localhost",
        "OrderNumber" : "o12345",
        "ProductName" : "Chicken"
}, { 
"_index" : "hello",
          "_type" : "logs",
          "_id" : "AVmxZxg-pyZuCjD89WOe",
          "_score" : 1.0,
          "_source" : {
            "message" : "o55631\Peanuts\r",
            "@version" : "1",
            "@timestamp" : "2017-01-18T11:47:20.518Z",
            "path" : "C:\\Elk\\logstash\\bin\\mylog.log",
            "host" : "localhost",
            "OrderNumber" : "o55631",
            "ProductName" : "Peanuts"

```

I am trying to Query this data in order to get the following result :

- If I purchase "chicken" what other products was purchased with chicken. So in actual fact i need to Query the order number for chicken which is **o12345** and bring back all products besides chicken.

**Example**

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

```

Now return all other products that was purchased with chicken which is Unique to o12345 which are

```
OrderNumber ProductName
    o12345	Apples
    o12345 Oranges
    o12345 Grapes

```

Please help i am new to elastic and unsure how to formulate this query.

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [January 19, 2017, 11:56am UTC](https://discuss.elastic.co/t/elasticsearch-jason-query-for-recommendations/72161/2 "2017-01-19T11:56:41Z")

</div>

I think I'm missing your question here. What do you want to accomplish?

As a general suggestion wrt. Elasticsearch and Recommendations you might want to check out [https://www.elastic.co/products/x-pack/graph](https://www.elastic.co/products/x-pack/graph)

Also there's a nice blog post over here detailing how to use significant terms aggregations for recommendations: [http://opensourceconnections.com/blog/2016/09/09/better-recsys-elasticsearch/](http://opensourceconnections.com/blog/2016/09/09/better-recsys-elasticsearch/)

Hope this helps as a getting started pointer,  
Isabel

---

<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 19, 2017, 12:01pm UTC](https://discuss.elastic.co/t/elasticsearch-jason-query-for-recommendations/72161/3 "2017-01-19T12:01:32Z")

</div>

@mainec Sorry about that i pressed the space bar by mistake and it uploaded my question while i was busy. I have completed the question now. please help i will really appreciate it.

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [January 19, 2017, 12:03pm UTC](https://discuss.elastic.co/t/elasticsearch-jason-query-for-recommendations/72161/4 "2017-01-19T12:03:13Z")

</div>

I think you really want to checkout both the graph plugin as well as the significant terms aggregation I mentioned earlier.

(About pressing space accidentally: No worries, those things happen 🙂 )

---

<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 19, 2017, 12:04pm UTC](https://discuss.elastic.co/t/elasticsearch-jason-query-for-recommendations/72161/5 "2017-01-19T12:04:23Z")

</div>

Thanks @mainec i will check that out now.

---

<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 16, 2017, 12:04pm UTC](https://discuss.elastic.co/t/elasticsearch-jason-query-for-recommendations/72161/6 "2017-02-16T12:04:27Z")

</div>

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