前提
最新版version7.5のElasticsearchとKibana利用しています。
以下のようなIndexを持っています。
参加者( attendee_id )をキーにした、その参加者がサービス内で拒否したいユーザIDのブラックリスト(assignee_blacklist)を持っています。
(下記テキストはKibana上で動くことを確認しています。)
DELETE /attendees ## Index作成 PUT /attendees { "mappings": { "properties": { "attendee_id": { "type": "keyword" }, "assignee_blacklist": { "type": "keyword" } } } } ## データ挿入 POST _bulk?refresh {"index":{"_index":"attendees", "_id":"1"}} { "attendee_id": "01-00-XXVoiuFdnizJxoJd7pvzZZ", "assignee_blacklist": [ "03-00-5", "03-00-6", "03-00-9" ] } {"index":{"_index":"attendees", "_id":"2"}} { "attendee_id": "01-00-YYVoiuFdnizJxoJd7pvzZZ", "assignee_blacklist": [ "03-00-5" ] } {"index":{"_index":"attendees", "_id":"3"}} { "attendee_id": "01-00-ZZVoiuFdnizJxoJd7pvzZZ", "assignee_blacklist": [] }
やりたいこと & 試していること
やりたいことは、ブラックリストに入っているユーザをごとに集約して、そのユーザをブロックしている参加者(attendee_id)情報を出すことです。
現状では以下のようなクエリを試しているのですが、
GET /attendees/_search { "query": { "match_all": {} }, "aggs": { "blocked_user": { "terms": { "field": "assignee_blacklist" } } } }
以下のような出力が得られます。
{ "took" : 22, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 3, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "attendees", "_type" : "_doc", "_id" : "1", "_score" : 1.0, "_source" : { "attendee_id" : "01-00-XXVoiuFdnizJxoJd7pvzZZ", "assignee_blacklist" : [ "03-00-5", "03-00-6", "03-00-9" ] } }, { "_index" : "attendees", "_type" : "_doc", "_id" : "2", "_score" : 1.0, "_source" : { "attendee_id" : "01-00-YYVoiuFdnizJxoJd7pvzZZ", "assignee_blacklist" : [ "03-00-5" ] } }, { "_index" : "attendees", "_type" : "_doc", "_id" : "3", "_score" : 1.0, "_source" : { "attendee_id" : "01-00-ZZVoiuFdnizJxoJd7pvzZZ", "assignee_blacklist" : [ ] } } ] }, "aggregations" : { "blocked_user" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "03-00-5", "doc_count" : 2 }, { "key" : "03-00-6", "doc_count" : 1 }, { "key" : "03-00-9", "doc_count" : 1 } ] } } }
期待すること
期待する(やりたい)結果は以下のようにkeyごとに元々のドキュメント情報があることです。
{ "took" : 55, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 3, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { ここのヒットの中身は既存と同じで良い(合ってもなくても良い) }, "aggregations" : { "blocked_user" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "03-00-5", "doc_count" : 2, "hits" : [ { "_index" : "attendees", "_type" : "_doc", "_id" : "1", "_score" : 1.0, "_source" : { "attendee_id" : "01-00-XXVoiuFdnizJxoJd7pvzZZ", "assignee_blacklist" : [ "03-00-5", "03-00-6", "03-00-9" ] }, }, { "_index" : "attendees", "_type" : "_doc", "_id" : "2", "_score" : 1.0, "_source" : { "attendee_id" : "01-00-YYVoiuFdnizJxoJd7pvzZZ", "assignee_blacklist" : [ "03-00-5" ] } } }, { "key" : "03-00-6", "doc_count" : 1 "hits": . 上記と同様にkeyがドキュメントの詳細を持っている . }, { "key" : "03-00-9", "doc_count" : 1, "hits": . 上記と同様にkeyがドキュメントの詳細を持っている . } ] } } }
開発しているサービスでは上記の期待することに出るような結果をそのまま使いたいと思っています。
上記の期待が得られるようなクエリを組むことは可能でしょうか?
また、Apache Solr などの他全文検索ミドルウェアとの対比もしているのですが、Solrならばこういった集約に関して強みがあるなどについても、ご存じであれば教えていただけると大変助かります。
あなたの回答
tips
プレビュー