Elasticsearch jason query for recommendations


(adhikar) #1

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.


(Isabel Drost-Fromm) #2

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

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/

Hope this helps as a getting started pointer,
Isabel


(adhikar) #3

@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.


(Isabel Drost-Fromm) #4

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 :slight_smile: )


(adhikar) #5

Thanks @mainec i will check that out now.


(system) #6

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