【问题标题】:Elasticsearch field not supported in range query范围查询中不支持 Elasticsearch 字段
【发布时间】:2018-02-26 12:39:39
【问题描述】:

我正在使用 curl 查询来尝试从我的 elasticsearch 实例中获取数据。我所有的索引和类型都有一个使用“strict_date_optional_time”格式的字段调用@timestamp。但是每次我尝试在该字段上使用范围过滤器时,我的查询都会失败。

我执行的查询:

curl 'localhost:X/logstash-*/traces_console/_search' -d '{
"query" : {
    "bool": {
        "must": [
            { "match_all": {} }
        ],
        "filter": [
            { "range":
                { "@timestamp": 
                    "gte": "2018-02-20T13:55:06.387Z",
                    "lte": "2018-02-23T13:55:06.387Z"
                }
            }
        ]
    }}
}'

错误信息:

"reason":{
    "type":"query_parsing_exception",
    "reason":"[range] query does not support [@timestamp]",
    "index":"logstash-2018.02.06","line":10,"col":21
}

我不明白为什么这个错误不断出现。当我查看已经发布的大部分内容时,所有使用日期格式的人都有工作查询。如果您对它为什么不起作用有任何提示或线索,我会很感激。

这里有一些有用的信息:

环境

  • 操作系统: Red Hat Enterprise Linux Server 6.5 版(圣地亚哥)
  • Java: 1.7
  • 弹性搜索: 2.4
  • Logstash: 2.4

从 logstash 生成的映射

"traces_console":{
    "properties":{
        "@timestamp":{
            "type":"date",
            "format":"strict_date_optional_time||epoch_millis"
        },
        "@version":{"type":"string"},
        "Method":{"type":"string"},
        "RequestSize":{"type":"string"},
        "ResponseSize":{"type":"string"},
        "ResponseTime":{"type":"string"},
        "SubSystem":{"type":"string"},
        "column1":{"type":"string"},
        "column2":{"type":"string"},
        "column3":{"type":"string"},
        "column4":{"type":"string"},
        "column5":{"type":"string"},
        "host":{"type":"string"},
        "path":{"type":"string"},
        "type":{"type":"string"}
    }
}

提供 elasticsearch 的 Logstash 配置文件

input {
  file {
    path => "LOG_PATH/TRACES_CONSOLE.log"
    start_position => "beginning"
    type => "traces_console"
  }
}

filter {
  csv {
    separator => ";"
    columns => ["Method","RequestSize","ResponseSize","ResponseTime","SubSystem"]
    source => message
    convert => {
      "RequestSize" => "date"
      "ResponseSize" => "date"
    }
    remove_field => ["message"]
  }
}

output {
  elasticsearch {
    hosts => ["localhost:X"]
  }
}

【问题讨论】:

    标签: curl elasticsearch logstash


    【解决方案1】:

    您的Range Query syntax 不正确,您需要额外的花括号:

    { "range":
         { "@timestamp": {
               "gte": "2018-02-20T13:55:06.387Z",
               "lte": "2018-02-23T13:55:06.387Z"
           }
         }
     }
    

    【讨论】:

    • 非常感谢,这就是问题所在!我觉得自己很愚蠢,但有时我会迷失在 curl 查询中的所有括号......
    • 是的,它有时会发生!我建议你使用某种 JSON 格式化程序,它对于复杂的查询非常有用。
    猜你喜欢
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多