2016-08-19 1 views
0

elasticsearchのインデックス作成時にデフォルトのマッピングダイナミックテンプレートを提供していて、それが期待どおりに機能するかどうかをチェックしたかったのです。私は困惑しました、どうすればそれを確認できますか? (ES 2.2.2を使用した作業) Elasticsearch、動的マッピングが機能するかどうかを確認する方法は?

"mappings": { 
    "_default_": { 
     "dynamic_templates": [ 
      { 
       "no_date_detection": { 
        "match_mapping_type": "string", 
        "mapping": { 
         "type": "string", 
         "date_detection": false 
        } 
       } 
      }, 
      { 
       "language_de": { 
        "match_mapping_type": "*", 
        "match": "*_de", 
        "mapping": { 
         "type": "string", 
         "analyzer": "german" 
        } 
       } 
      }, 
      { 
       "language_es": { 
        "match":    "*_es", 
        "match_mapping_type": "*", 
        "mapping": { 
         "type":   "string", 
         "analyzer":  "spanish" 
        } 
       } 
      }, 
      { 
       "language_en": { 
        "match":    "*_en", 
        "match_mapping_type": "*", 
        "mapping": { 
         "type":   "string", 
         "analyzer":  "english" 
        } 
       } 
      } 
     ] 
    } 
} 

それはマニュアルに記載されている例のように、非常に簡単です。

マッピングは、動的テンプレートが新しいタイプに

"testobject": { 
    "dynamic_templates": [ 
     { 
      "no_date_detection": { 
      "mapping": { 
       "type": "string", 
       "date_detection": false 
      }, 
      "match_mapping_type": "string" 
      } 
     }, 
     { 
      "language_de": { 
     ... 

を伝承していることを示して取得しかし、私は 「description_en」のような新しいフィールドを持つオブジェクトを作成するとき:「いくつかの英語のテキスト」 をしてマッピングをGETその中に「英語」 :それはちょうど、これが 「アナライザー」を持つべきではない

 "description_en": { 
      "type": "string" 
     } 

を示して?

私は何が間違っていましたか、ダイナミックマッピングが正しい場合、どのように適用されることを確認できますか?事前に

感謝/カーステン私の質問として


「どのように私はそれが適用されることを確認することができますか?」不明のようだ、私は簡単にするために試してみてください。

  1. 私はデフォルト動的マッピングを使用して索引を作成します。
  2. "testobject"タイプを作成します。
  3. "GET/myindex/testobject/_mappings"は、期待どおりに動的テンプレートが型に渡されることを検証します。
  4. 私はtestobject型のオブジェクトに新しいフィールドを作成します。
  5. "GET/myindex/testobject/_mappings"には新しいフィールドが表示されますが、ではなく、と言うと 'date_detection':false 'と表示されます。単純な文字列として表示します(上記参照)。

ダイナミックテンプレートが新しく作成されたフィールドに適用されたかどうかを確認するにはどうすればよいですか?


簡体例:

PUT /myindex 
{ 
    "mappings": { 
     "_default_": { 
      "dynamic_templates": [ 
       { 
        "no_date_detection": { 
         "match_mapping_type": "string", 
         "mapping": { 
          "type": "string", 
          "date_detection": false 
         } 
        } 
       } 
      ] 
     } 
    } 
} 


PUT /myindex/gardeners/1 
{ 
    "name": "gary" 
} 

GET /myindex/_mapping 

{ 
    "myindex": { 
     "mappings": { 
     "gardeners": { 
      "dynamic_templates": [ 
       { 
        "no_date_detection": { 
        "mapping": { 
         "type": "string", 
         "date_detection": false 
        }, 
        "match_mapping_type": "string" 
        } 
       } 
      ], 
      "properties": { 
       "name": { 
        "type": "string" 
       } 
      } 
     }, 
     "_default_": { 
      "dynamic_templates": [ 
       { 
        "no_date_detection": { 
        "mapping": { 
         "type": "string", 
         "date_detection": false 
        }, 
        "match_mapping_type": "string" 
        } 
       } 
      ] 
     } 
     } 
    } 
} 

私の新しいフィールド "名前"

"properties": { 
    "name": { 
     "type": "string" 
    } 
} 

doen'tのマッピングは、それが受け継がれないのはなぜ "date_detection": false が含まれていますか?

答えて

0

私は私の仮定に誤りが見つかりました:"date_detection": falseはそのように動作しません。 with dynamic_templates

マッピングで直接date_detectionを指定する必要があります(特定のタイプのレベルではない)。 https://www.elastic.co/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html

インデックスを自動的に新しいインデックスに追加したい場合は、インデックステンプレートを使用できます。はい、本当です、しかし、私はその後.._マッピングを取得するときにどちらのルールが現れるなぜそれは私の質問に答えていないヒント(https://discuss.elastic.co/t/mappings--default--dynamic-templates-doesnt-show-up-in-resulting-mapping/59030

0

ダイナミックテンプレートは、定義されている順にチェックされ、最初に一致するテンプレートが適用されます。

no_date_detectionテンプレートは、stringですので、テンプレートdescription_enと一致しています。

あなたは、そのフィールドがenglishアナライザで使用したい場合は、あなたがテンプレートの順序を変更する必要があります。

"mappings": { 
    "_default_": { 
     "dynamic_templates": [ 
     { 
      "language_de": { 
      "match_mapping_type": "*", 
      "match": "*_de", 
      "mapping": { 
       "type": "string", 
       "analyzer": "german" 
      } 
      } 
     }, 
     { 
      "language_es": { 
      "match": "*_es", 
      "match_mapping_type": "*", 
      "mapping": { 
       "type": "string", 
       "analyzer": "spanish" 
      } 
      } 
     }, 
     { 
      "language_en": { 
      "match": "*_en", 
      "match_mapping_type": "*", 
      "mapping": { 
       "type": "string", 
       "analyzer": "english" 
      } 
      } 
     }, 
     { 
      "no_date_detection": { 
      "match_mapping_type": "string", 
      "mapping": { 
       "type": "string", 
       "date_detection": false 
      } 
      } 
     } 
     ] 
    } 
    } 
+0

ためのヤニックへ

感謝。どのルールが適用されているかを確認/確認するにはどうすればよいですか? –

+0

「どちらのルールも表示されません」とはどういう意味ですか?フィールドのマッピングは、ルールが適用されたかどうかの証明です。また、インデックス/タイプ(存在しない場合はあなたのタイプに対して自動的に作成されるマッピング)のマッピングでは、 'dynamic_templates'セクションで定義された動的テンプレートが表示されます。 –

+0

私はあなたのことを聞いていますが、私の質問がどうやってあいまいなのか分かりません。 (私は私の質問を上げようとしています(上記参照)。 –

関連する問題