2017-09-27 3 views
0

매우 큰 데이터 집합을 가지고 있으므로 match 절 (1300 년경)을 많이 사용하는 elasticsearch 쿼리가 있습니다.bool match 절을 리펙토링하여 maxClauseCount를 방지하는 Elasticsearch

"error": { 
    "root_cause": [ 
     { 
     "type": "too_many_clauses", 
     "reason": "too_many_clauses: maxClauseCount is set to 1024" 
     } 
    ], 
    "type": "search_phase_execution_exception", 
    "reason": "all shards failed", 
    "phase": "query", 
    "grouped": true, 
} 

나는 온라인으로 몇 가지 조사를하고는 maxClauseCount을 높일 수있는 좋은 방법이 아닙니다 발견 : ES는이 없다는 오류가 발생합니다. 일부는 elastic에서 bool이 아닌 terms 쿼리로 내 쿼리를 다시 작성해야한다고 언급했습니다. 다음은 내 검색어의 예입니다. maxClauseCount에 맞지 않도록 다시 쓰려면 어떻게해야합니까? 용어 (들) 쿼리에 일치하는 쿼리를 전환

{ 
    "query": { 
    "bool": { 
     "must_not": [ 
     { 
      "match": { 
      "city": "dallas" 
      } 
     }, 
     { 
      "match": { 
      "city": "london" 
      } 
     }, 
     { 
      "match": { 
      "city": "singapore" 
      } 
     }, 
     { 
      "match": { 
      "city": "prague" 
      } 
     }, 
     { 
      "match": { 
      "city": "ontario" 
      } 
     }, 
     ........................................... 
     ........................................... 
     ........................................... 
     ] 
    } 
    } 
} 
+1

는 검색이 정확히 일치를 사용하고 (용어 쿼리 ... 등, 대소 문자를 구분) 경기 분석되지 않은 경우에만 OK입니다. 이것이 사실이라면 실제로 이것은 절 수를 줄이는 쉬운 방법입니다. – GPI

답변

1
POST test/_search 
{ 
    "query": { 
    "bool": { 
     "must_not": [ 
     { 
      "terms": { 
      "city": [ 
       "prague", 
       "london", 
       "chicago", 
       "singapore", 
       "new york", 
       "san francisco", 
       "mexico city", 
       "baghdad" 
      ] 
      } 
     } 
     ] 
    } 
    } 
}