2016-11-09 135 views
0

我对ES很新。我使用https://github.com/dariusk/corpora/blob/master/data/humans/us_presidents.json作为学习集。更新文档的ElasticSearch/Kibana字段

起初我在Kibana进入这个在开发工具选项卡:

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 
     } 
     ... 
     } 
} 

然后我意识到,如果我想补充个别校长更多的数据,我倒是应该这样做:

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 
     } 
} 

好的,所以ES接受了更新。

但是现在,当我进入Kibana的管理/索引模式时,我看到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

相关问题