Elasticsearch 中的数字范围/过滤器
Number ranges / filters in Elasticsearch
我正在尝试在 elasticsearch 中建立索引,然后搜索数字字段。结果集为空,即使逻辑结果是有 1 条记录的结果集。
下面动作重现(用sense)
创建索引
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"
}
}
}
}
}
}
}
}
在日期范围内搜索工作正常,return输入预期数据
POST playground/doc/_search
{
"query": {
"filtered": {
"filter": {
"range" : {
"value.datelabel" : {
"lte": "now-28y"
}
}
}
}
}
}
但数值范围不会return任何结果
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": []
}
}
有什么建议吗?
您刚刚拼错了。 "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"
}
}
}
]
}
}
您有错字:numerlabel
- numberlabel
。给定映射的正确查询是:
{
"query": {
"filtered": {
"filter": {
"range": {
"value.numerlabel": {
"lte": 100
}
}
}
}
}
}
我正在尝试在 elasticsearch 中建立索引,然后搜索数字字段。结果集为空,即使逻辑结果是有 1 条记录的结果集。
下面动作重现(用sense)
创建索引
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"
}
}
}
}
}
}
}
}
在日期范围内搜索工作正常,return输入预期数据
POST playground/doc/_search
{
"query": {
"filtered": {
"filter": {
"range" : {
"value.datelabel" : {
"lte": "now-28y"
}
}
}
}
}
}
但数值范围不会return任何结果
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": []
}
}
有什么建议吗?
您刚刚拼错了。 "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"
}
}
}
]
}
}
您有错字:numerlabel
- numberlabel
。给定映射的正确查询是:
{
"query": {
"filtered": {
"filter": {
"range": {
"value.numerlabel": {
"lte": 100
}
}
}
}
}
}