执行查询时弹出搜索错误

时间:2014-05-22 07:18:54

标签: elasticsearch

我尝试使用弹性搜索执行以下查询

http://192.168.110.127:9200/testingrepo/logfiles/_search?pretty



{
    "query" : {
        "filtered" : {
                 'query': {
                            'query_string': {
                                        'query': 'request: WORD'
                              }
                   },
            "filter" : {
                "range" : {
                    "date" : {
                        "gte" : 1400376899.0,
                        "lte"  : 1400722499.0
                    }
                }
            }
        }
    }
}

但是我收到了错误

{
   "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[BKeGm20mTPyDPn1iIipjrg][testingrepo][3]: SearchParseException[[testingrepo][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{ "query" : { "filtered" : { 'query': { 'query_string': { 'query': "request:WORD" } }, "filter" : { "range" : { "date" : { "gte" : 1400376899.0, "lte" : 1400722499.0 } } } } } }]]]; nested: QueryParsingException[[testingrepo] Failed to parse]; nested: JsonParseException[Unexpected character (''' (code 39)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name at [Source: [B@21668a99; line: 4, column: 14]]; }{[BKeGm20mTPyDPn1iIipjrg][testingrepo][0]: SearchParseException[[testingrepo][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{ "query" : { "filtered" : { 'query': { 'query_string': { 'query': "request:WORD" } }, "filter" : { "range" : { "date" : { "gte" : 1400376899.0, "lte" : 1400722499.0 } } } } } }]]];

我不确定出了什么问题。尝试了各种组合Same Query在pyelasticsearch客户端中的工作。

2 个答案:

答案 0 :(得分:0)

由于" \ n"生成了查询解析错误和空白字符。例如,您需要删除换行符和空格,以便从命令行使用CURL。

答案 1 :(得分:0)

您需要使用双引号'替换filtered查询部分中的单引号"。这就是您收到错误的原因。试试这个:

{
    "query" : {
        "filtered" : {
                 "query": {
                            "query_string": {
                                        "query": "request: WORD"
                              }
                   },
            "filter" : {
                "range" : {
                    "date" : {
                        "gte" : 1400376899.0,
                        "lte"  : 1400722499.0
                    }
                }
            }
        }
    }
}