Elasticsearch中的数字范围/过滤器
问题描述:
我试图在elasticsearch中建立一个索引,然后搜索数字字段。结果集是空的,即使你的逻辑结果是有一个记录结果集。Elasticsearch中的数字范围/过滤器
下面的操作来再现(使用感)
创建索引
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": [] } }
任何建议为什么?
答
你有一个错字:numerlabel
- numberlabel
。正确的查询,给定映射是:
{
"query": {
"filtered": {
"filter": {
"range": {
"value.numerlabel": {
"lte": 100
}
}
}
}
}
}
答
您刚刚拼错了拼写。 "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"
}
}
}
]
}
}
+0
谢谢斯隆,我检查了查询的拼写100次......但没有看文档的创建。非常感谢!由于安德烈只是早一点,我会接受他的答案 - 你的答案同样正确:) –
谢谢安德烈 - 我检查了100次查询的拼写......但没有看文档的创建。非常感谢! –