Elasticsearch中的数字范围/过滤器
我试图在elasticsearch中建立一个索引,然后搜索数值字段。结果集为空,即使逻辑结果为1记录结果集也是如此 下面是要复制的动作(使用感官) 创建索引Elasticsearch中的数字范围/过滤器,search,elasticsearch,numeric,Search,elasticsearch,Numeric,我试图在elasticsearch中建立一个索引,然后搜索数值字段。结果集为空,即使逻辑结果为1记录结果集也是如此 下面是要复制的动作(使用感官) 创建索引 PUT playground 创建文档 POST playground/doc { "value": { "textlabel": "Lorem Ipsum", "numerlabel": 37.0, "datelabel":"1978-10-26T00:00:00+02:00" } }
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.numberlabel" : {
"lte": 100
}
}
}
}
}
}
搜索日期范围工作正常,返回预期数据
POST playground/doc/_search
{
"query": {
"filtered": {
"filter": {
"range" : {
"value.datelabel" : {
"lte": "now-28y"
}
}
}
}
}
}
但数值范围不返回任何结果
{
"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.numberlabel" : {
"lte": 100
}
}
}
}
}
}
导致
有什么建议吗?你刚才拼错了<代码>文档中的“numerlabel”,但查询中的“value.numerlabel” 在我运行了您的设置代码之后,这可以工作:
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
-numerlabel
。如果映射为:
{
"query": {
"filtered": {
"filter": {
"range": {
"value.numerlabel": {
"lte": 100
}
}
}
}
}
}
谢谢Sloan,我检查了100次查询的拼写。。。但是没有查看文档创建。谢谢!由于Andrei只是稍早一点,我接受他的答案-你的答案同样正确:)谢谢你Andrei-我检查了100次查询的拼写。。。但是没有查看文档创建。谢谢!