Elasticsearch 未显示任何命中。 Python 查询正确
Elasticsearch not showing any hits. Python Query is correct
首先post。
我知道之前有人问过这个问题,但我根据以前的解决方案修改了我的代码,但这仍然没有用,并且该线程已关闭,所以我正在创建一个新的。请多多包涵。
我 运行 python 中的以下代码没有出现匹配。我 运行 在 kibana 上进行相同的查询,我得到了所有结果。请让我知道我在这里做错了什么:
import elasticsearch
from elasticsearch import Elasticsearch, RequestsHttpConnection
from datetime import datetime
es = Elasticsearch(hosts=[{"host": "localhost", "port": 9200}], connection_class=RequestsHttpConnection, request_timeout=30)
doc = {'author': 'vaibhav','text': 'event',"timestamp": datetime.now()}
res = es.index(index="radius_ml_posts", id = 1, body = doc)
res = es.search(index="radius_ml_posts", size = 100, body={ "query": {
"query_string": {
"default_field": "search_text",
"query": "thai food"
}
}
}
)
当我 运行 它时,我得到以下输出:
res
Out[50]:
{'took': 10,
'timed_out': False,
'_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0},
'hits': {'total': {'value': 0, 'relation': 'eq'},
'max_score': None,
'hits': []}}
我知道有数据,查询正确,我可以在kibana上确认。
感谢您的意见。谢谢
我修好了。原来需要刷新索引。
es.indices.refresh(index="my_index")
这成功了。
首先post。
我知道之前有人问过这个问题,但我根据以前的解决方案修改了我的代码,但这仍然没有用,并且该线程已关闭,所以我正在创建一个新的。请多多包涵。
我 运行 python 中的以下代码没有出现匹配。我 运行 在 kibana 上进行相同的查询,我得到了所有结果。请让我知道我在这里做错了什么:
import elasticsearch
from elasticsearch import Elasticsearch, RequestsHttpConnection
from datetime import datetime
es = Elasticsearch(hosts=[{"host": "localhost", "port": 9200}], connection_class=RequestsHttpConnection, request_timeout=30)
doc = {'author': 'vaibhav','text': 'event',"timestamp": datetime.now()}
res = es.index(index="radius_ml_posts", id = 1, body = doc)
res = es.search(index="radius_ml_posts", size = 100, body={ "query": {
"query_string": {
"default_field": "search_text",
"query": "thai food"
}
}
}
)
当我 运行 它时,我得到以下输出:
res
Out[50]:
{'took': 10,
'timed_out': False,
'_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0},
'hits': {'total': {'value': 0, 'relation': 'eq'},
'max_score': None,
'hits': []}}
我知道有数据,查询正确,我可以在kibana上确认。
感谢您的意见。谢谢
我修好了。原来需要刷新索引。
es.indices.refresh(index="my_index")
这成功了。