ElasticSearch多層nested查詢、nested過濾排除非結果內容
示例mappings 下 fragment 是nested型別,fragment.tagTree也是巢狀型別
"mappings" : {
"properties" : {
"content" : {
"type" : "text",
"analyzer" : "ik_max_custom",
"search_analyzer" : "ik_smart"
},
"id" : {
"type" : "keyword"
},
"fragment" : {
"type" : "nested",
"properties" : {
"content" : {
"type" : "text",
"analyzer" : "ik_max_custom",
"search_analyzer" : "ik_smart"
},
"id" : {
"type" : "integer"
},
"tagTree" : {
"type" : "nested",
"properties" : {
"tag_id" : {
"type" : "integer"
},
"tag_name" : {
"type" : "keyword"
},
"tag_path" : {
"type" : "keyword"
}
}
},
"title" : {
"type" : "text",
"analyzer" : "ik_max_word",
"search_analyzer" : "ik_smart"
}
}
}
}
}
查詢多層巢狀
- 示例
是否計算得分需自行考慮{ "constant_score": { "filter": { "nested": { "path": "fragment", "query": { "nested": { "path": "fragment.tagTree", "query": { "terms": { "fragment.tagTree.tag_id": [927597] } } } } } }, "boost": 0 } }
巢狀過濾結果值
-
例如一個文件,根據fragment.tagTree.tag_id=930365查詢,預期結果是隻有fragment.id=111,不想要fragment.id=222,因為都在一個文件中,如果不過濾那麼結果中會包含id =1這個文件的所有內容
{ "fragment" : [ { "tagTree" : [ { "tag_name" : "北京", "tag_id" : 930365, "tag_path" : "930364" } ], "id" : 111, "content" : "1111", }, { "tagTree" : [ ], "id" : 222, "content" : "2222" } ], "id" : 1, "title" : "示例結果" }
-
操作
- “inner_hits”:可以實現如上結果
- ““inner_hits”: {“size”:0}”:可以實現分類
一個查詢中同一個欄位只能有一個inner_hits
{ "constant_score": { "filter": { "nested": { "path": "fragment", "query": { "nested": { "path": "fragment.tagTree", "query": { "terms": { "fragment.tagTree.tag_id": [111] } } } }, "inner_hits": {} } }, "boost": 0 } }
相關文章
- 關於 Elasticsearch nested field /script 的一些複雜查詢Elasticsearch
- Elasticsearch 7.x Nested 巢狀型別查詢 | ES 乾貨Elasticsearch巢狀型別
- Elasticsearch——filter過濾查詢ElasticsearchFilter
- Elasticsearch 查詢與過濾Elasticsearch
- ES查詢之查詢屬性過濾、結果高亮顯示
- es針對nested型別資料無法進行過濾查詢的問題記錄型別
- mysql查詢結果多列拼接查詢MySql
- 統計資訊過期導致SQL進行NESTED LOOPS查詢緩慢SQLOOP
- nested loop心得OOP
- mysql多條件過濾查詢之mysq高階查詢MySql
- [翻譯]ElasticSearch官方文件-執行查詢和過濾操作Elasticsearch
- DBeaver 匯出多個查詢結果集
- UPDATE查詢結果範圍內的資料
- Elasticsearch 查詢結果分組統計,聚合檢索(group by stats)Elasticsearch
- 【sql調優之執行計劃】nested loops join and nested loop join outerSQLOOP
- 資料庫表--nested table資料庫
- NESTED LOOPS 成本計算OOP
- 【筆記】forall and nested table and cursor筆記
- search(16)- elastic4s-內嵌檔案:nested and joinAST
- sphinx查詢過濾問題
- Elasticsearch 複合查詢——多字串多欄位查詢Elasticsearch字串
- JAVA + Oracle儲存過程返回查詢結果集JavaOracle儲存過程
- 查詢某個儲存過程有哪些內容儲存過程
- 34. 過濾條件、多表查詢、子查詢
- navicat 匯出查詢結果
- mysql匯出查詢結果MySql
- JS 根據彙總結果過濾JS
- treevalue——Master Nested Data Like TensorAST
- HASH JOIN ,MERGE JOIN ,NESTED LOOPOOP
- [轉]Trees in SQL: Nested Sets and Materialized PathSQLZed
- Elasticsearch 單字串多欄位查詢Elasticsearch字串
- elasticsearch之單請求多查詢Elasticsearch
- 儲存過程結果進行查詢 select 存過過程儲存過程
- Ms Sql Server查詢儲存過程中的內容SQLServer儲存過程
- tcpdump過濾資料包,結果不對?TCP
- Mybatis模糊查詢結果為空MyBatis
- ps aux查詢結果解釋UX
- nested exception is IncompleteElementException: Could not find parameter mapException