2016-06-25 4 views
3

데이터를 분석하지 않고 대/소문자를 구분하지 않는 필터를 사용하여 검색하려면 어떻게합니까? 예 : 이 예에서는 대문자로 인해 "델리"와 "델리"가 별개의 항목으로 표시됩니다.인덱스가없는 필드에 대/소문자를 구분하지 않음 검색

new york 2 
Delhi 1 
delhi 1 
new Jersey 1 

예상 결과 :

new york 2 
delhi 2 
new jersey 1 

나는 소문자 분석을 시도하지만 내가 별도의 도시로 "새"를 반환하고 잘못 것이다 분석에 인덱스를 변경해야합니다.

DELETE /test_index 
PUT /test_index 
{ 
    "mappings": { 
     "doc": { 
     "properties": { 
      "cities": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
     } 
     } 
    } 
} 

POST /test_index/doc/_bulk 
{"index":{"_id":1}} 
{"cities":["new york", "delhi"]} 
{"index":{"_id":2}} 
{"cities":["new york", "Delhi", "new Jersey"]} 


POST /test_index/_search?search_type=count 
{ 
    "aggs": { 
     "city_terms": { 
      "terms": { 
       "field": "cities" 
      } 
}}} 

답변

2

네,하지만 당신은 여전히 ​​not_analyzed과 똑같은 일을하지만 귀하의 의견 lowercases keyword 분석이 필요합니다

PUT /test_index 
{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "keyword": { 
      "type": "custom", 
      "tokenizer": "keyword", 
      "filter": ["lowercase"] 
     } 
     } 
    } 
    }, 
    "mappings": { 
     "doc": { 
     "properties": { 
      "cities": { 
       "type": "string", 
       "analyzer": "keyword" 
      } 
     } 
     } 
    } 
} 

UPDATE를

ES 5까지, 당신이 할 수있는 다음을 수행하십시오 :

POST /test_index/_search?search_type=count 
{ 
    "aggs": { 
     "city_terms": { 
      "terms": { 
       "script": "doc.cities.values.collect{it.toLowerCase()}" 
      } 
}}} 
+0

오류 # "이유": "분석기 [분석기] 필드 [도시]에 대해 찾을 수 없습니다" – shantanuo

+0

내 잘못, 내 대답을 업데이 트했습니다. – Val

+0

이번에는 오류가 발생하지 않습니다. 그러나 나는 아직도 잘못된 결과를 얻는다. 버전 # 2.3.3 – shantanuo

관련 문제