[英]Query DSL not working in pyes search
我正在嘗試使用自定義查詢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
}
}
}
}
}
}'
這里的想法是在許多分類的文檔中搜索與特定字符串查詢匹配的所有文檔。 然后,使用聚合,我想按類別查找生成的前五個文檔。 已加注星標的項目會使其顯示在其他搜索結果的上方。
當我直接在終端中輸入上面列出的命令時,此方法效果很好,但是當我嘗試將其放入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]]; }]
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"]; }]
ElasticSearchException: ElasticsearchParseException[Expected field name but got START_OBJECT "aggs"]; }]
這些錯誤以及pyes似乎還沒有“ topFoundHits”功能這一事實(我認為)使我受挫。
有什么想法為什么會發生以及如何解決? 非常感謝!
我使用此庫開始工作,您可以在其中使用常規查詢dsl JSON語法: http : //elasticsearch-dsl.readthedocs.org/en/latest/ 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.