カスタム クエリ DSL を使用して、pyes ライブラリを使用して結果を取得しようとしています。コマンドラインを使用するときに機能するクエリ DSL があります。
curl -XGET localhost:9200/test_index/_search -d '{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"field_value_factor": {
"field": "starred",
"modifier": "none",
"factor": 2
}
}
},
"aggs" : {
"types" : {
"filters" : {
"filters" : {
"category1" : { "type" : { "value" : "category1"}},
"category2" : { "type" : { "value" : "category2"}},
"category3" : { "type" : { "value" : "category3"}},
"category4": { "type" : { "value" : "category4"}},
"category5" : { "type" : { "value" : "category5"}}
}
},
"aggs": {
"topFoundHits": {
"top_hits": {
"size": 5
}
}
}
}
}
}'
ここでの考え方は、特定の文字列クエリに一致するすべてのドキュメントについて、分類された多くのドキュメントを検索することです。次に、集計を使用して、結果の上位 5 つのドキュメントをカテゴリ別に見つけたいと思います。スター付きのアイテムはブーストされ、他の検索結果の上に表示されます。
これは、上記のコマンドをターミナルで直接入力するとうまく機能しますが、pyes に入れようとすると機能しません。どうするのが一番いいのかわかりません。pyes ライブラリのドキュメントは、これを完全に pyes オブジェクトに変換するのが非常にわかりにくいです。
私は次のことをしようとしています:
query_dsl = self.get_text_index_query_dsl()
resulting_docs = conn.search(query=query_dsl)
(self.get_test_index_query_dsl
上記のクエリ DSL dict を返します)
そのまま検索すると、次のようになります。
ElasticSearchException: QueryParsingException[[test_index] No query registered for [query]]; }]
親の「クエリ」マッピングを削除して試してみると:
query_dsl = {
"function_score": {
"query": {
"match_all": {}
},
"field_value_factor": {
"field": "starred",
"modifier": "none",
"factor": 2
}
},
"aggs" : {
"types" : {
"filters" : {
"filters" : {
"category1" : { "type" : { "value" : "category1"}},
"category2" : { "type" : { "value" : "category2"}},
"category3" : { "type" : { "value" : "category3"}},
"category4": { "type" : { "value" : "category4"}},
"category5" : { "type" : { "value" : "category5"}}
}
},
"aggs": {
"topFoundHits": {
"top_hits": {
"size": 5
}
}
}
}
}
}
これも次のようにエラーになります。ElasticSearchException: ElasticsearchParseException[Expected field name but got START_OBJECT "aggs"]; }]
pyes にはまだ「topFoundHits」機能がないように見えるという事実に加えて、これらのエラー (私は思う) が私を支えています。
なぜこれが起こっているのか、それを修正する方法はありますか? どうもありがとう!