Join query in ElasticSearch

后端 未结 3 2170
离开以前
离开以前 2020-11-27 20:42

Is there any way (query) to join 2 JSONs below in ElasticSearch

{
product_id: \"1111\",
price: \"23.56\",
stock: \"100\"
}

{
product_id: \"1111\",
category:         


        
3条回答
  •  伪装坚强ぢ
    2020-11-27 21:10

    isaac.hazan's answer works quite well, but I would like to add a few points that helped me with this kind of situation:

    I landed on this page when I was trying to solve a similar problem, in that I had to exclude multiple records of one index based on documents of another index. The lack of relationships is one of the main downsides of unstructured databases.

    The elasticsearch documentation page on Handling Relationships explains a lot.

    Four common techniques are used to manage relational data in Elasticsearch:

    • Application-side joins
    • Data denormalization
    • Nested objects
    • Parent/child relationships

    Often the final solution will require a mixture of a few of these techniques.

    I've used nested objects and application-side joins, mostly. While using the same field name could momentarily solve the problem, I think it is better to rethink and create best-suited mapping for your application.

    For instance, you might find that you want to list all products with price greater than x, or list all products that are not in stock anymore. To deal with such scenarios it helps if you are using one of the solutions mentioned above.

提交回复
热议问题