2016-11-09 8 views
0

私は非常にESに慣れています。私はhttps://github.com/dariusk/corpora/blob/master/data/humans/us_presidents.jsonを学習セットとして使用しています。文書更新時のElasticSearch/Kibanaフィールド

は、最初に私はKibanaにおける開発ツール]タブでこれを入力する:

POST /presidents/president/1 
{ 
     "website":"", 
     "startdate":"2009-01-20", 
     "role_type_label":"President", 
     "enddate":"2013-01-20", 
     "description":"President", 
     "district":null, 
     "phone":null, 
     "title":"President", 
     "congress_numbers":[ 
      111, 
      112, 
      113 
     ], 
     "title_long":"President", 
     "current":false, 
     "person":{ 
      "name":"President Barack Obama [D]", 
      "firstname":"Barack", 
      "twitterid":null, 
      "middlename":"", 
      "gender":"male", 
      "bioguideid":"O000167", 
      "namemod":"", 
      "birthday":"1961-08-04", 
      "link":"https://www.govtrack.us/congress/members/barack_obama/400629", 
      "youtubeid":null, 
      "sortname":"Obama, Barack (President) [D]", 
      "lastname":"Obama", 
      "gender_label":"Male", 
      "osid":"N00009638", 
      "pvsid":"9490", 
      "nickname":"", 
      "id":400629, 
      "cspanid":null 
     } 
} 

POST /presidents/president/1 
{ "bo" : 
     { 
     "website":"", 
     "startdate":"2009-01-20", 
     "role_type_label":"President", 
     "enddate":"2013-01-20", 
     "description":"President", 
     "district":null, 
     "phone":null, 
     "title":"President", 
     "congress_numbers":[ 
      111, 
      112, 
      113 
     ], 
     "title_long":"President", 
     "current":false, 
     "person":{ 
      "name":"President Barack Obama [D]", 
      "firstname":"Barack", 
      "twitterid":null, 
      "middlename":"", 
      "gender":"male", 
      "bioguideid":"O000167", 
      "namemod":"", 
      "birthday":"1961-08-04", 
      "link":"https://www.govtrack.us/congress/members/barack_obama/400629", 
      "youtubeid":null, 
      "sortname":"Obama, Barack (President) [D]", 
      "lastname":"Obama", 
      "gender_label":"Male", 
      "osid":"N00009638", 
      "pvsid":"9490", 
      "nickname":"", 
      "id":400629, 
      "cspanid":null 
     } 
     ... 
     } 
} 

は、それから私は、私は、個々の大統領についてのより多くのデータを追加したい場合は、私はむしろこれを行う必要があることに気づきましたOK、ESはアップデートをうまく受け入れました。

しかし、私は木場の管理/索引パターンに行くと、person.lastnamebo.person.lastnameの両方のフィールドが表示されます。

なぜ前のフィールドが残っていますか?更新されたドキュメントに含まれていないフィールドをESが保持するのは正常ですか?

また、今日の選挙結果については、例外的に面白いものは別として、明らかにご質問ください。

答えて

1

これは、Elasticsearchの正常な動作です。

ESは、デフォルトで、挿入するデータを動的にマッピングします。インデックス内の同じタイプの複数のオブジェクトにインデックスを付けると、これらのオブジェクトはすべて同じマッピングを共有します。意図は、オブジェクトが挿入され、その型の潜在的なフィールドのすべてを必ずしも保持せず、インデックスに挿入されることを可能にすることです。

インデックスを作成するとき、またはインデックスの新しいタイプを定義するときに、自分でマッピングを定義することができます。マッピングはいくつかの注意点を含めて更新することもできます。

GET /tk_file.2016/TK_FILE/_mapping 

あなたの応答は次のようになります:あなたがのためのマッピングのセットを持っていることをここ

{ 
    "presidents": { 
     "mappings": { 
     "president": { 
      "properties": { 
       "bo": { 
        "properties": { 
        "congress_numbers": { 
         "type": "long" 
        }, 
        "current": { 
         "type": "boolean" 
        }, 
        "description": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "enddate": { 
         "type": "date" 
        }, 
        "person": { 
         "properties": { 
          "bioguideid": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "birthday": { 
           "type": "date" 
          }, 
          "firstname": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "gender": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "gender_label": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "id": { 
           "type": "long" 
          }, 
          "lastname": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "link": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "middlename": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "name": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "namemod": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "nickname": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "osid": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "pvsid": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          }, 
          "sortname": { 
           "type": "text", 
           "fields": { 
           "keyword": { 
            "type": "keyword", 
            "ignore_above": 256 
           } 
           } 
          } 
         } 
        }, 
        "role_type_label": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "startdate": { 
         "type": "date" 
        }, 
        "title": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "title_long": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "website": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        } 
        } 
       }, 
       "congress_numbers": { 
        "type": "long" 
       }, 
       "current": { 
        "type": "boolean" 
       }, 
       "description": { 
        "type": "text", 
        "fields": { 
        "keyword": { 
         "type": "keyword", 
         "ignore_above": 256 
        } 
        } 
       }, 
       "enddate": { 
        "type": "date" 
       }, 
       "person": { 
        "properties": { 
        "bioguideid": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "birthday": { 
         "type": "date" 
        }, 
        "firstname": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "gender": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "gender_label": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "id": { 
         "type": "long" 
        }, 
        "lastname": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "link": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "middlename": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "name": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "namemod": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "nickname": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "osid": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "pvsid": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        }, 
        "sortname": { 
         "type": "text", 
         "fields": { 
          "keyword": { 
           "type": "keyword", 
           "ignore_above": 256 
          } 
         } 
        } 
        } 
       }, 
       "role_type_label": { 
        "type": "text", 
        "fields": { 
        "keyword": { 
         "type": "keyword", 
         "ignore_above": 256 
        } 
        } 
       }, 
       "startdate": { 
        "type": "date" 
       }, 
       "title": { 
        "type": "text", 
        "fields": { 
        "keyword": { 
         "type": "keyword", 
         "ignore_above": 256 
        } 
        } 
       }, 
       "title_long": { 
        "type": "text", 
        "fields": { 
        "keyword": { 
         "type": "keyword", 
         "ignore_above": 256 
        } 
        } 
       }, 
       "website": { 
        "type": "text", 
        "fields": { 
        "keyword": { 
         "type": "keyword", 
         "ignore_above": 256 
        } 
        } 
       } 
      } 
     } 
     } 
    } 
} 

お知らせ次のコマンドを実行し、あなたのインデックス内のタイプのマッピングを表示するには

boオブジェクトとそれに関連するサブフィールドと、後続のドキュメントの各フィールドのマッピングを持ちます。これが動的マッピングの効果です。

このマッピングの柔軟性を無効にするには、動的マッピングを明示的に無効にし、ドキュメントの構造をデータ型を含めて自分で定義することができます。現在のマッピングで定義されているように、bioguideidをテキストではなく整数にすることをお勧めしますか?私はMappings APIにあなたを案内します。

関連する問題