2017-02-28 4 views
3

キーワードタイプフィールドで大文字と小文字を区別しない集計を試みていますが、これを動作させる際に問題があります。Elasticsearch 5.2.2:集計の大文字と小文字を区別しない

私が今まで試したのは、「キーワード」トークナイザと「小文字」フィルタを使用する「小文字」というカスタムアナライザを追加することでした。次に、作業したいフィールドの「use_lowercase」というマッピングにフィールドを追加しました。フィールド内の用語を検索したいので、既存の「テキスト」と「キーワード」フィールドコンポーネントも保持したいと思っていました。ここで

は、カスタム・アナライザを含むインデックスの定義、次のとおりです。これまでのところは良い

POST authors/famousbooks/1 
{ 
    "Book": "The Mysterious Affair at Styles", 
    "Year": 1920, 
    "Price": 5.92, 
    "Genre": "Crime Novel", 
    "Author": "Agatha Christie" 
} 

POST authors/famousbooks/2 
{ 
    "Book": "And Then There Were None", 
    "Year": 1939, 
    "Price": 6.99, 
    "Genre": "Mystery Novel", 
    "Author": "Agatha christie" 
} 

PUT authors 
{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "lowercase": { 
      "type": "custom", 
      "tokenizer": "keyword", 
      "filter": "lowercase" 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "famousbooks": { 
     "properties": { 
     "Author": { 
      "type": "text", 
      "fields": { 
      "keyword": { 
       "type": "keyword", 
       "ignore_above": 256 
      }, 
      "use_lowercase": { 
       "type": "text", 
       "analyzer": "lowercase" 
      } 
      } 
     } 
     } 
    } 
    } 
} 

は今、私は同じ著者とが、異なる場合と2件のレコードを追加します。私は、著者に基づいて用語の集約を行う

GET authors/famousbooks/_search 
{ 
    "size": 0, 
    "aggs": { 
    "authors-aggs": { 
     "terms": { 
     "field": "Author.use_lowercase" 
     } 
    } 
    } 
} 

場合、私は次のような結果を得る今:

{ 
    "error": { 
    "root_cause": [ 
     { 
     "type": "illegal_argument_exception", 
     "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [Author.use_lowercase] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory." 
     } 
    ], 
    "type": "search_phase_execution_exception", 
    "reason": "all shards failed", 
    "phase": "query", 
    "grouped": true, 
    "failed_shards": [ 
     { 
     "shard": 0, 
     "index": "authors", 
     "node": "yxcoq_eKRL2r6JGDkshjxg", 
     "reason": { 
      "type": "illegal_argument_exception", 
      "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [Author.use_lowercase] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory." 
     } 
     } 
    ], 
    "caused_by": { 
     "type": "illegal_argument_exception", 
     "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [Author.use_lowercase] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory." 
    } 
    }, 
    "status": 400 
} 

をだから、凝集が検索フィールドではなくテキストであると考えているように私には思えますキーワードとなり、フィールドデータの警告が表示されます。私は、ESは、用語フィールドが実際には(カスタムアナライザを介して)キーワードであり、集約可能であることを認識するほど洗練されていると思うだろうが、そうではないようだ。

Authorのマッピングに「"fielddata":true」を追加すると、集計はうまくいきますが、この値を設定する際にヒープ使用量が高いことを警告しているので、これをすることを躊躇しています。

このタイプの非機密キーワードアグリゲーションのベストプラクティスはありますか?私はとのマッピングセクションにちょうどいいと思っていましたが、そうは思われません。

私は"fielddata":trueルートに行くと、これを動作させるには大きすぎるスティックを使用する必要があるように感じます。これについての助けに感謝します!

答えて

0

さてあなたは、テキストとしてuse_lowercase定義しました:

"use_lowercase": { "type": "text", "analyzer": "lowercase" }

type: keywordとしてそれを定義してください - それは私が仕分けとしていた同様の問題で私を助けました。

+0

、。 マッピングを設定する際のエラーメッセージ: [fields]のマッピング定義にサポートされていないパラメータがあります:[analyzer:lowercase] – GoodEnuf

2

解決策は、カスタムアナライザの代わりにカスタムノーマライザを使用することです。

PUT authors 
{ 
    "settings": { 
    "analysis": { 
     "normalizer": { 
     "myLowercase": { 
      "type": "custom", 
      "filter": [ "lowercase" ] 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "famousbooks": { 
     "properties": { 
     "Author": { 
      "type": "text", 
      "fields": { 
      "keyword": { 
       "type": "keyword", 
       "ignore_above": 256 
      }, 
      "use_lowercase": { 
       "type": "keyword", 
       "normalizer": "myLowercase", 
       "ignore_above": 256 
      } 
      } 
     } 
     } 
    } 
    } 
} 

これにより、フィールドAuthor.use_lowercaseを使用して集計が可能になりました。代わりに、タイプ `のkeyword`:(私は小文字の部分が仕事を得るために、ここでやっているよう)あなたも、同様アナライザを指定した場合text`が失敗した`タイプを指定残念ながら

関連する問題