gpt4 book ai didi

json - 如何按JSON中的嵌套字段进行搜索

转载 作者:行者123 更新时间:2023-12-03 01:43:32 25 4
gpt4 key购买 nike

我有看起来像的文件:

λ curl -XGET -u elastic:elasticpassword 192.168.1.71:9200/mytweets/ex3/_search?pretty -H "Content-Type: application/json" -d'{"query":{"match_all":{}}}'
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "mytweets",
"_type" : "ex3",
"_id" : "AV4PXt6Be-9TCGhLorhI",
"_score" : 1.0,
"_source" : {
"10" : {
"id" : 10,
"name" : "f1",
"value" : "some_v"
},
"20" : {
"id" : 20,
"name" : "f2",
"value" : "some_val"
}
}
}
]
}
}

我想搜索所有字段 10.value的值类似于 *some*的文档:
{
"query": {
"nested": {
"path": "10",
"query": {
"wildcard": {
"value": "*some*"
}
}
}
}
}

但是得到错误:
λ curl -XGET -u elastic:elasticpassword 192.168.1.71:9200/mytweets/ex3/_search -H "Content-Type: application/json" -d'{ "query": { "nested": { "path": "10", "query": { "wildcard": { "value": "*some*" }}}}}'
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"failed to create query: {\n \"nested\" : {\n \"query\" : {\n \"wildcard\" : {\n \"value\" : {\n \"wildcard\" : \"*some*\",\n \"boost\" : 1.0\n }\n }\n },\n \"path\" : \"10\",\n \"ignore_unmapped\" : false,\n \"score_mode\" : \"avg\",\n \"boost\" : 1.0\n }\n}","index_uuid":"OGa3zCZoQ3GjAGdpIXiIfw","index":"mytweets"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"mytweets","node":"d6mbNtxERmuOnAN7YYvumg","reason":{"type":"query_shard_exception","reason":"failed to create query: {\n \"nested\" : {\n \"query\" : {\n \"wildcard\" : {\n \"value\" : {\n \"wildcard\" : \"*some*\",\n \"boost\" : 1.0\n }\n }\n },\n \"path\" : \"10\",\n \"ignore_unmapped\" : false,\n \"score_mode\" : \"avg\",\n \"boost\" : 1.0\n }\n}","index_uuid":"OGa3zCZoQ3GjAGdpIXiIfw","index":"mytweets","caused_by":{"type":"illegal_state_exception","reason":"[nested] nested object under path [10] is not of nested type"}}}]},"status":400}

为什么?我该如何解决?

最佳答案

您需要在映射中将10字段的类型显式设置为nested

PUT mytweets
{
"mappings": {
"ex3": {
"properties": {
"10": {
"type": "nested"
}
}
}
}
}

关于json - 如何按JSON中的嵌套字段进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45842009/

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