2014-10-06 117 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" 
     } 
    } 
    } 
}