2014-10-06 101 views
0

我的查询有什么问题?我只想要查询返回具有以下条件的文档: language_id = 28和[225,226,227]中的publisher_id,最后计算统计信息。我就是这么做的:弹性搜索和过滤器

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "term": { 
      "language_id": 28 
     } 
     }, 
     "filter": { 
     "and": [ 
      { 
      "range": { 
       "re_max": { 
       "gt": 100 
       } 
      } 
      }, 
      "terms": { 
      "publihser_id": [ 
       225, 
       226, 
       227 
      ] 
      } 
     } 
     ] 
    } 
    } 
}, 
"aggs": { 
    "stat_agg": { 
    "stats": { 
     "field": "re_max" 
    } 
    } 
} 
} 

它产生的错误:

{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[CebklbvjR2ORQkaiUEm6eQ][rep][0]: SearchParseException[[rep][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [ {\r\n  \"query\": {\r\n  \"filtered\": {\r\n   \"query\": {\r\n   \"term\": {\r\n    \"language_id\": 28\r\n   }\r\n   },\r\n   \"filter\": {\r\n   \"and\": [\r\n    {\r\n    \"range\": {\r\n     \"re_max\": {\r\n     \"gt\": 100\r\n     }\r\n    }\r\n    },\r\n    \"terms\": {\r\n    \"publihser_id\": [\r\n     225,\r\n     226,\r\n     227\r\n    ]\r\n    }\r\n   }\r\n   ]\r\n  }\r\n  }\r\n },\r\n \"aggs\": {\r\n  \"stat_agg\": {\r\n  \"stats\": {\r\n   \"field\": \"re_max\"\r\n  }\r\n  }\r\n }\r\n }]]]; nested: QueryParsingException[[rep] Failed to parse]; nested: JsonParseException[Unexpected character (':' (code 58)): was expecting comma to separate ARRAY entries\n at [Source: [[email protected]; line: 18, column: 23]]; }{[CebklbvjR2ORQkaiUEm6eQ][rep][4]: SearchParseException[[rep][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [ {\r\n  \"query\": {\r\n  \"filtered\": {\r\n   \"query\": {\r\n   \"term\": {\r\n    \"language_id\": 28\r\n   }\r\n   },\r\n   \"filter\": {\r\n   \"and\": [\r\n    {\r\n    \"range\": {\r\n     \"re_max\": {\r\n     \"gt\": 100\r\n     }\r\n    }\r\n    },\r\n    \"terms\": {\r\n    \"publihser_id\": [\r\n     225,\r\n     226,\r\n     227\r\n    ]\r\n    }\r\n   }\r\n   ]\r\n  }\r\n  }\r\n },\r\n \"aggs\": {\r\n  \"stat_agg\": {\r\n  \"stats\": {\r\n   \"field\": \"re_max\"\r\n  }\r\n  }\r\n }\r\n }]]]; nested: QueryParsingException[[rep] Failed to parse]; nested: JsonParseException[Unexpected character (':' (code 58)): was expecting comma to separate ARRAY entries\n at [Source: [[email protected]; line: 18, column: 23]]; }{[CebklbvjR2ORQkaiUEm6eQ][rep][3]: SearchParseException[[rep][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [ {\r\n  \"query\": {\r\n  \"filtered\": {\r\n   \"query\": {\r\n   \"term\": {\r\n    \"language_id\": 28\r\n   }\r\n   },\r\n   \"filter\": {\r\n   \"and\": [\r\n    {\r\n    \"range\": {\r\n     \"re_max\": {\r\n     \"gt\": 100\r\n     }\r\n    }\r\n    },\r\n    \"terms\": {\r\n    \"publihser_id\": [\r\n     225,\r\n     226,\r\n     227\r\n    ]\r\n    }\r\n   }\r\n   ]\r\n  }\r\n  }\r\n },\r\n \"aggs\": {\r\n  \"stat_agg\": {\r\n  \"stats\": {\r\n   \"field\": \"re_max\"\r\n  }\r\n  }\r\n }\r\n }]]]; nested: QueryParsingException[[rep] Failed to parse]; nested: JsonParseException[Unexpected character (':' (code 58)): was expecting comma to 
+0

问题是什么?不管用?给错误? etc – 2014-10-06 07:21:43

+0

错误已更新 – 2014-10-06 07:29:09

回答

0

它应该是这样的(语法,明智的) - 你缺少一个 “{”:

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "term": { 
      "language_id": 28 
     } 
     }, 
     "filter": { 
     "and": [ 
      { 
      "range": { 
       "re_max": { 
       "gt": 100 
       } 
      } 
      }, 
      { 
      "terms": { 
       "publihser_id": [ 
       225, 
       226, 
       227 
       ] 
      } 
      } 
     ] 
     } 
    } 
    }, 
    "aggs": { 
    "stat_agg": { 
     "stats": { 
     "field": "re_max" 
     } 
    } 
    } 
}