2016-06-25 12 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とまったく同じ仕事をしていませんが、あなただけの入力を小文字にkeywordアナライザ必要があります:あなたができるES 5、まで

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

UPDATE

をこれを行う:

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

関連する問題