gpt4 book ai didi

python - Elasticsearch Percolate查询没有命中

转载 作者:行者123 更新时间:2023-12-02 22:35:19 30 4
gpt4 key购买 nike

我试图从使用python运行的Elastic 7.3 Percolate Documentation中获取示例,但是我的文档没有遇到任何查询。
这是查看示例页面的链接:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-percolate-query.html

我使用了python pip包elasticsearch。
我的结果是:

{'took': 1, 'timed_out': False, '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 0, 'relation': 'eq'}, 'max_score': None, 'hits': []}}

索引包含一个文档(渗滤查询):
curl -X GET“localhost:9200 / inverse-index / _search”
{"took":112,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"inverse-index","_type":"_doc","_id":"1","_score":1.0,"_source":{"query":{"match":{"message":"bonsai tree"}}}}]}}

预先谢谢您(请参阅下面的代码)

from elasticsearch import Elasticsearch

elasticHost = "localhost"
elasticPort = "9200"
elasticIndex = "inverse-index"

if __name__ == "__main__":

es = Elasticsearch(elasticHost + ":" + elasticPort)
if es.indices.exists(elasticIndex):
print("deleting '%s' index..." % elasticIndex)
res = es.indices.delete(index=elasticIndex)
print(" response: '%s'" % res)

request_body = {
"mappings": {
"properties": {
"message": {
"type": "text"
},
"query": {
"type": "percolator"
}
}
}
}

print("creating '%s' index..." % elasticIndex)
print(" response: '%s'" % (es.indices.create(index=elasticIndex, body=request_body)))

res = es.create(index=elasticIndex, id=1, body={
"query" : {
"match" : {
"message" : "bonsai tree"
}
}
})

doc = {
"query": {
"percolate": {
"field": "query",
"document": {
"message": "A new bonsai tree in the office"
}
}
}
}

res = es.search(index=elasticIndex, body=doc)
print(str(res))

日志信息:
send: b'GET /inverse-index/_search HTTP/1.1\r\nHost: localhost:9200\r\nAccept-Encoding: identity\r\nContent-Length: 78\r\nconnection: keep-alive\r\ncontent-type: application/json\r\n\r\n'
send: b'{"query":{"percolate":{"field":"query","document":{"message":"bonsai tree"}}}}'
DEBUG:urllib3.connectionpool:http://localhost:9200 "GET /inverse-index/_search HTTP/1.1" 200 160
INFO:elasticsearch:GET http://localhost:9200/inverse-index/_search [status:200 request:0.008s]
DEBUG:elasticsearch:> {"query":{"percolate":{"field":"query","document":{"message":"bonsai tree"}}}}
DEBUG:elasticsearch:< {"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":0,"relation":"eq"},"max_score":null,"hits":[]}}
reply: 'HTTP/1.1 200 OK\r\n'

示例页面的代码可与bash curl命令配合使用。问题可能在python网站上。

最佳答案

案件结案。
flex 索引是在后台创建的,我只需要等待几秒钟。不知道是否有证明的选择,是否已经完成创建,但是对我有用。

关于python - Elasticsearch Percolate查询没有命中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57430925/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com