【发布时间】:2016-12-25 07:21:26
【问题描述】:
第一步:
在弹性搜索上创建索引 http://localhost:9200/shop 带有下面的 mapping.json
{
"cloth" :
{
"properties" :
{
"name" : { "type" : "string", "index" : "analyzed" },
"variation" :
{
"type" : "nested",
"properties" :
{
"size" :
{
"type" : "string", "index" : "not_analyzed"
},
"color" :
{
"type" : "string", "index" : "not_analyzed"
}
}
}
}
}
}
获取:http://localhost:9200/shop/_mapping/cloth
HTTP/1.1 200 正常 内容类型:应用程序/json;字符集=UTF-8 内容长度:518
{"shop":{"mappings":{"cloth":{"properties":{"cloth":{"properties":{"properties":{"properties":{"name":{"属性":{"index":{"type":"string"},"type":{"type":"string"}}},"variation":{"properties":{"properties":{"属性":{"color":{"properties":{"index":{"type":"string"},"type":{"type":"string"}}},"size":{"属性":{"index":{"type":"string"},"type":{"type":"string"}}}}},"type":{"type":"string"}} }}}}},"name":{"type":"string"},"variation":{"properties":{"color":{"type":"string"},"size":{" type":"string"}}}}}}}}
第 2 步:
使用下面给出的 data.json 插入数据 http://localhost:9200/shop/cloth/?_create
{
"name" : "Test shirt",
"variation" : [
{ "size" : "XXL", "color" : "red" },
{ "size" : "XL", "color" : "black" }
]
}
第 3 步:
尝试使用给定的 query.json 进行搜索
http://localhost:9200/shop/cloth/_search
{
"query" : {
"nested" : {
"path" : "variation",
"query" : {
"bool" : {
"must" : [
{ "term" : { "variation.size" : "XXL" } },
{ "term" : { "variation.color" : "black" } }
]
}
}
}
}
}
出现以下错误
HTTP/1.1 400 错误请求 内容类型:应用程序/json;字符集=UTF-8 内容长度:519
{"error":{"root_cause":[{"type":"query_parsing_exception","reason":"[nested] nested object under path [variation] is not of nested type","index":"shop","line":4,"col":1}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"shop","node":"6U9SA_SDRJKfw1bRxwH8ig","reason":{"type":"query_parsing_exception","reason":"[nested] nested object under path [variation] is not of nested type","index":"shop","line":4,"col":1}}]},"status":400}
嵌套查询的搜索方式是什么?有没有合适的方法将映射文件加载到搜索集群中?
【问题讨论】:
-
你能用
curl -XGET localhost:9200/shop/_mapping/cloth的输出更新你的问题吗? -
我们如何插入映射,就像使用带有 mapping.json 内容的 POST 一样
-
我的错,对不起,请再次查看我上面的评论。
-
请运行这个:
curl -XGET localhost:9200/shop/_mapping/cloth我不认为是这样 -
@Val 我有一个简单的问题:如果在映射文件中声明更多字段并在索引数据库上发布更少的列并在索引上执行搜索是否会引发与上述问题相同的错误?跨度>
标签: json elasticsearch