转:elasticsearch nested嵌套查询
生活随笔
收集整理的這篇文章主要介紹了
转:elasticsearch nested嵌套查询
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉自:
【弄nèng - Elasticsearch】DSL入門篇(七)—— Nested類型查詢,聚合_司馬缸砸缸了-CSDN博客文章目錄1. nested query2. nested 對象聚合項目推薦nested類型就是為了解決object類型在對象數組上丟失關聯性的問題的,如果將字段設置為nested類型,那個每一個嵌套對象都會被索引為一個 “隱藏的獨立文檔”。他會為每一個內部對象屬性單獨索引。如果你需要保留 object 數組中每個對象的內部關系, 則需要使用 nested 類型, 而不是 [object,ob...https://blog.csdn.net/yy756127197/article/details/103258404
?? nested類型就是為了解決object類型在對象數組上丟失關聯性的問題的,如果將字段設置為nested類型,那個每一個嵌套對象都會被索引為一個 “隱藏的獨立文檔”。他會為每一個內部對象屬性單獨索引。
如果你需要保留 object 數組中每個對象的內部關系, 則需要使用 nested 類型, 而不是[object,object] 類型.
【1】嵌套查詢-nested query
添加nested屬性
PUT schools/_mapping/classes {"properties": {"users": {"type": "nested"}} }添加數據
POST schools/classes/11 {"classes_id": 11,"name": "班級11","address": "深圳市福田區福華路11","price": 11.4,"timestamp": 1572573660000,"users" : [{"name" : "SIMA","age" : "11","price" : 13.4},{"name" : "LIYAO","age" : "13","price" : 13.2}] }查詢(注意把 must放在 filter或constant_score里面,因為filter不計算評分,效率高)
POST schools/classes/_search {"query": {"nested" : {"path" : "users","query" : {"bool" : {"must" : [{ "match" : {"users.name" : "SIMA"} },{ "range" : {"users.price" : {"gte" : 11,"lte" : 15}} }]}}}} }2. nested 對象聚合
POST schools/classes/_search {"size": 0, "aggs": {"nested": {"nested": {"path": "users"},"aggs": {"amount_avg": {"avg": {"field": "users.price"}}}}} }總結
以上是生活随笔為你收集整理的转:elasticsearch nested嵌套查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 王朔作品 王朔简介
- 下一篇: 手机总是发烫是什么情况