python - Python,为什么 Elasticsearch 不根据给定的查询返回记录?
问题描述
我是弹性搜索的新手,我正在尝试通过多匹配查询获取数据。
以下数据示例:
{
.......
"_source": {
"itemid": 40233,
"value": "176016",
}
}
{
.......
"_source": {
"itemid": 40238,
"value": "176016",
}
}
{
"_index": "uint-2018-12-04",
.......
"_source": {
"itemid": 40203,
"value": "176016",
}
}
我的代码:
def __init__(self, CustomerName, DeviceID):
self.client = Elasticsearch(hosts=['***.***.***.***'])
self.search = Search(using=self.client, index="ind-*").extra(size=50)
def get_data_test(self):
self.search.query("match", itemid=40233)
response = self.search.execute()
for hitX in response.hits.hits:
print(hitX)
它有效,但没有返回预期的记录,它返回所有记录
解决方案
该query
方法返回对象的副本Search
。你需要做:
s = self.search.query("match", itemid=40233)
response = s.execute()
...
推荐阅读
- c# - 使用异步 API 调用好不好?
- python - 让“python”短语指的是 Linux 上的 Python 3?
- java - 如何通过Java8流中的属性计算对象分组中的多个总和?
- odoo - 如果基于用户选择具有不同字段的相同名称,如何隐藏按钮
- python-3.x - 如何并行化 geopandas“to_file”函数
- loops - 嵌套 for 循环的运行时复杂度,但内部循环仅上升到外部循环的当前索引
- android - RecyclerView GridLayoutManager 项目装饰占用测量空间?
- opengl-es-2.0 - 如何在金属中禁用深度测试但启用更新深度纹理(如 glDepthMask(GL_TRUE))?
- python - 如何在循环中找到包含 2 个标签的块?
- javascript - 如何解决Outlook中自定义表格标签不兼容问题