elasticsearch的join查询
生活随笔
收集整理的這篇文章主要介紹了
elasticsearch的join查询
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.概述
官方文檔
https://www.elastic.co/guide/en/elasticsearch/reference/current/joining-queries.html
兩種類型的查詢
嵌套查詢
has_child和has_parent
其中,has_child返回包含特定查詢字段文檔的父文檔;
has_parent返回包含特定查詢字段的父文檔的子文檔。
?
2.實例
2.1 嵌套查詢
GET /_search {"query": {"nested" : {"path" : "obj1","score_mode" : "avg","query" : {"bool" : {"must" : [{ "match" : {"obj1.name" : "blue"} },{ "range" : {"obj1.count" : {"gt" : 5}} }]}}}} }2.2?has_child?查詢
GET /_search {"query": {"has_child" : {"type" : "blog_tag","query" : {"term" : {"tag" : "something"}}}} }2.3?has_parent?
GET /_search {"query": {"has_parent" : {"parent_type" : "blog","query" : {"term" : {"tag" : "something"}}}} }2.4?parent_id?查詢
?
PUT my_index {"mappings": {"_doc": {"properties": {"my_join_field": {"type": "join","relations": {"my_parent": "my_child"}}}}} }PUT my_index/_doc/1?refresh {"text": "This is a parent document","my_join_field": "my_parent" }PUT my_index/_doc/2?routing=1&refresh {"text": "This is a child document","my_join_field": {"name": "my_child","parent": "1"} }?
?
GET /my_index/_search {"query": {"parent_id": {"type": "my_child","id": "1"}} }?
轉載于:https://www.cnblogs.com/davidwang456/p/10078301.html
總結
以上是生活随笔為你收集整理的elasticsearch的join查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: lucene源码分析(8)MergeSc
- 下一篇: 并发工具类(三)控制并发线程数的Sema