![](/img/trans.png)
[英]Java Hibernate HQL SQL INNER JOIN query not working- Oracle
[英]Elasticsearch nested mapping query not working- JAVA?
我已將我的一個字段設置為嵌套類型。 我按照這個文檔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] 下得到 [nested] 嵌套對象不是嵌套類型。
我正在使用 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"
}
}
}
}
}
}
數據.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
你需要像這樣修復你的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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.