我已将我的一个字段设置为嵌套类型。 我按照此文档https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-joining-queries.html#java-query-dsl-nested-query
进行了跟踪以下是摘录
"price":{
"type":"nested",
"properties":{
"activity_price":{
"type":"double"
},
"multimedia_price":{
"type":"double"
},
"transportation_price":{
"type":"double"
}
}
}
执行查询时
QueryBuilders.nestedQuery("price", QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("price.activity_price", price)),
ScoreMode.Max);
我得到路径[price]下的[嵌套]嵌套对象不是嵌套类型。
我正在使用Elasticsearch 5.1.2
我创建索引,映射和填充数据的三个文件: - 的 mapping.json
{
"settings":{
"number_of_shards":1,
"number_of_replicas":0
},
"mappings":{
"test_type_table":{
"price":{
"type":"nested",
"properties":{
"activity_price":{
"type":"double"
},
"multimedia_price":{
"type":"double"
},
"transportation_price":{
"type":"double"
}
}
}
}
}
}
data.json
{ "index" : { "_index" : "test_index", "_type" : "test_type_table", "_id" : "1" } }
{"price": [{"activity_price":"100.00","multimedia_price":"10","transporation_price":"10"}]}
和 setup.json
curl -XPOST http://localhost:9200/test_index -d @mapping.json
curl -s -XPOST http://localhost:9200/_bulk --data-binary @data.json
答案 0 :(得分:1)
您需要像这样修复mapping.json
文件:
{
"settings":{
"number_of_shards":1,
"number_of_replicas":0
},
"mappings":{
"test_type_table":{
"properties": { <--- this is missing
"price":{
"type":"nested",
"properties":{
"activity_price":{
"type":"double"
},
"multimedia_price":{
"type":"double"
},
"transportation_price":{
"type":"double"
}
}
}
}
}
}
}
然后,您可以使用PUT
而不是POST
# first delete your index
curl -XDELETE http://localhost:9200/test_index
# recreate your index using PUT
curl -XPUT http://localhost:9200/test_index -d @mapping.json