我正在尝试让ElasticSearch在我的盒子上工作。我有以下映射:
{
"sneakers" : {
"mappings" : {
"sneaker" : {
"properties" : {
"brand" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "integer",
"index" : "no"
},
"title" : {
"type" : "string"
}
}
}
}
}
}
}
}
因此,我有一个带有“运动鞋”类型的“运动鞋”索引,具有一个带有“ id”和“ title”的“ brand”属性。
检查运动鞋是否存在,运行curl -XGET'http :// localhost:9200 / sneakers / sneaker / 1?pretty ',我得到:
{
"_index" : "sneakers",
"_type" : "sneaker",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"brand" : {
"id" : 1,
"title" : "Nike"
}
}
}
现在,运行curl -XGET'http :// localhost:9200 / sneakers / _search?q = brand.title = adidas&pretty '我得到:
{
"took" : 13,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1330,
"max_score" : 0.42719018,
"hits" : [ {
"_index" : "sneakers",
"_type" : "sneaker",
"_id" : "19116",
"_score" : 0.42719018,
"_source" : {
"brand" : {
"id" : 2,
"title" : "Adidas"
}
}
}, ...
}
但是,一旦我开始像这样使用Query DSL:
curl -XGET 'http://localhost:9200/sneakers/_search?pretty' -d '{
"query" : {
"term" : { "brand.title" : "adidas" }
}
}
'
我懂了
{
"took" : 9,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
以某种方式,即使运行最简单的查询,查询DSL也从不返回任何内容。我正在运行ES 2.3.1。
知道为什么Query DSL无法正常工作吗?我究竟做错了什么?
您已将brand
字段映射为nested
类型,因此需要使用query进行nested
查询,如下所示:
curl -XGET 'http://localhost:9200/sneakers/_search?pretty' -d '{
"query" : {
"nested": {
"path": "brand",
"query": {
"term" : { "brand.title" : "adidas" }
}
}
}
}
'
注意:如果"type": "nested"
从映射中删除,则查询将起作用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句