我正在尝试在elasticsearch中构建索引并在之后搜索数字字段。结果集为空,即使逻辑结果是1记录结果集。
重现动作(使用感觉)
创建索引
PUT playground
创建文档
POST playground/doc
{
"value": {
"textlabel": "Lorem Ipsum",
"numerlabel": 37.0,
"datelabel":"1978-10-26T00:00:00+02:00"
}
}
自动生成的映射文件似乎提供了正确的数据类型
{
"playground": {
"mappings": {
"doc": {
"properties": {
"value": {
"properties": {
"datelabel": {
"type": "date",
"format": "dateOptionalTime"
},
"numerlabel": {
"type": "double"
},
"textlabel": {
"type": "string"
}
}
}
}
}
}
}
}
搜索日期范围正常,返回预期数据
POST playground/doc/_search
{
"query": {
"filtered": {
"filter": {
"range" : {
"value.datelabel" : {
"lte": "now-28y"
}
}
}
}
}
}
但数字范围不会返回任何结果
POST playground/doc/_search
{
"query": {
"filtered": {
"filter": {
"range": {
"value.numberlabel" : {
"lte": 100
}
}
}
}
}
}
导致
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
有什么建议吗?
答案 0 :(得分:1)
你刚刚拼错了。您的文档中为"numerlabel"
,但查询中为"value.numberlabel"
。
运行您的设置代码后,这可行:
POST playground/doc/_search
{
"query": {
"filtered": {
"filter": {
"range": {
"value.numerlabel" : {
"lte": 100
}
}
}
}
}
}
...
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "playground",
"_type": "doc",
"_id": "AU5UiwngQAg_uFp56nys",
"_score": 1,
"_source": {
"value": {
"textlabel": "Lorem Ipsum",
"numerlabel": 37,
"datelabel": "1978-10-26T00:00:00+02:00"
}
}
}
]
}
}
答案 1 :(得分:1)
你有一个拼写错误:numerlabel
- numberlabel
。鉴于映射是正确的查询:
{
"query": {
"filtered": {
"filter": {
"range": {
"value.numerlabel": {
"lte": 100
}
}
}
}
}
}