我對彈性搜索比較陌生。我可以在開發工具中進行簡單的查詢。我需要幫助將以下 sql 轉換為 es 查詢
select c.conversationid from conversations c
where c.conversationid not in
(select s.conversationid from conversations s
where s.type='end' and s.conversationid=c.conversationid)
索引如下所示。
| 對話ID | 型別 |
|---|---|
| 1 | 開始 |
| 2 | 開始 |
| 1 | 結尾 |
| 3 | 開始 |
如果我執行上述查詢,我??將得到以下結果。
對話ID
2
3
uj5u.com熱心網友回復:
我用過以下
- 術語聚合
- 桶選擇器
詢問
{
"aggs": {
"conversations": {
"terms": {
"field": "conversationid",
"size": 10
},
"aggs": { --> subaggregation where type == end
"types": {
"terms": {
"field": "type.keyword",
"include": [
"end"
],
"size": 10
}
},
"select": { --> select those terms where there is no bucket for "end"
"bucket_selector": {
"buckets_path": {
"path": "types._bucket_count"
},
"script": "params.path==0"
}
}
}
}
}
}
結果
"aggregations" : {
"conversations" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 2,
"doc_count" : 1,
"types" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ ]
}
},
{
"key" : 3,
"doc_count" : 1,
"types" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ ]
}
}
]
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/516200.html
標籤:弹性搜索
