我使用以下代码将json文件(如下所示)推送到ES:
with open('test.json','rb') as payload:
headers = {'content-type': 'application/json'}
r = requests.post('http://localhost:9200/test_nest_json/1',data=payload, verify=False, headers=headers)
{
"data": [
{
"keyword": "abc",
"lists": [
{
"item_val": "some_val"
}
],
"another_key": "some_key"
},
{
"keyword": "xyz",
"lists": [
{
"item_val":"another_val"
}
],
"another_key": "pqr"
}
]
}
我尝试更新映射并使用了term
查询,但仍然导致显示所有索引。我无法使用词条查询来查询像"data.keyword" = "abc"
这样的一个关键字。
最佳答案
看起来您的嵌套对象有问题
https://www.elastic.co/guide/en/elasticsearch/guide/current/nested-objects.html
The reason for this cross-object matching, as discussed in Arrays of Inner Objects, is that our beautifully structured JSON document is flattened into a simple key-value format in the index
因此,存储的有效文档如下所示:
{
"data.keyword": [ abc, xyz ],
"data.another_key": [ some_key, pqr ],
}
这意味着您发布的查询将与任何文档匹配,只要至少一个嵌套对象的包含xyz关键字即可。我建议阅读上面的链接进行澄清。
关于json - 搜索使用json文件创建的 Elasticsearch 索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42310611/