logstash - Join query in ElasticSearch -


is there way (query) join 2 jsons below in elasticsearch

{ product_id: "1111", price: "23.56", stock: "100" }  { product_id: "1111", category: "iphone case", manufacturer: "belkin" } 

above 2 jsons processed (input) under 2 different types in logstash, indexes available in different 'type' filed in elasticsearch.

what want join 2 jsons on product_id field.

it depends intend when join. elasticsearch not regular database supports join between tables. text search engine manages documents within indexes.

on other hand can search within same index on multiple types using fields common every type.

for example taking data can create index 2 types , data follows:

curl -xpost localhost:9200/product -d '{     "settings" : {         "number_of_shards" : 5     } }'  curl -xpost localhost:9200/product/type1/_mapping -d '{         "type1" : {             "properties" : {                 "product_id" : { "type" : "string" },                 "price" : { "type" : "integer" },                 "stock" : { "type" : "integer" }             }         }    }'                curl -xpost localhost:9200/product/type2/_mapping -d '{         "type2" : {             "properties" : {                 "product_id" : { "type" : "string" },                 "category" : { "type" : "string" },                 "manufacturer" : { "type" : "string" }             }         } }'    curl -xpost localhost:9200/product/type1/1 -d '{         product_id: "1111",          price: "23",         stock: "100" }'  curl -xpost localhost:9200/product/type2/1 -d '{         product_id: "1111",         category: "iphone case",         manufacturer: "belkin" }' 

i created 1 index called product 2 type type1 , type2. can following query , return both documents:

curl -xget 'http://localhost:9200/product/_search?pretty=1' -d '{     "query": {         "query_string" : {             "query" : "product_id:1111"         }     } }'  {   "took" : 95,   "timed_out" : false,   "_shards" : {     "total" : 5,     "successful" : 5,     "failed" : 0   },   "hits" : {     "total" : 2,     "max_score" : 0.5945348,     "hits" : [ {       "_index" : "product",       "_type" : "type1",       "_id" : "1",       "_score" : 0.5945348, "_source" : {     product_id: "1111",     price: "23",     stock: "100" }     }, {       "_index" : "product",       "_type" : "type2",       "_id" : "1",       "_score" : 0.5945348, "_source" : {     product_id: "1111",     category: "iphone case",     manufacturer: "belkin" }     } ]   } } 

the reason because elasticsearch search on documents within index regardless of type. still different join in sense elasticsearch not going cartesian product of documents belong each type.

hope helps


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -