Elasticsearch未显示任何匹配。 Python查询正确

问题描述 投票:0回答:1

第一篇文章。

我知道这已经被问过了,但是我根据以前的解决方案对代码进行了修改,但是仍然无法正常工作,并且该线程已关闭,因此我正在创建一个新线程。请忍受。

我在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上确认。

感谢您的投入。谢谢。

python elasticsearch information-retrieval
1个回答
0
投票

我修复了它。原来需要刷新的索引。

es.indices.refresh(index="my_index")

这成功了。

© www.soinside.com 2019 - 2024. All rights reserved.