Elasticsearch Reference【6.1】Mapping

來源:互聯網
上載者:User

標籤:ali   相關   格式   破壞   customize   sep   tar   https   img   

Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. For instance, use mappings to define:which string fields should be treated as full text fields.which fields contain numbers, dates, or geolocations.whether the values of all fields in the document should be indexed into the catch-all _all field.the format of date values.custom rules to control the mapping for dynamically added fields.

  映射是定義一個文檔和他所包含的欄位是如何儲存和索引的過程。例如,使用映射來定義:

    》哪些字串應該被視為一個整體、不被分割

    》哪些欄位包含數字、日期或者地理資訊

    》文檔中的欄位值是否應該被索引到匹配所有的域中

    》日期值的格式

    》自訂規則控制動態添加欄位的映射

 

Mapping TypeEach index has one mapping type which determines how the document will be indexed.[6.0.0] Deprecated in 6.0.0. See Removal of mapping types 
A mapping type has:1、Meta-fields  Meta-fields are used to customize how a document’s metadata associated is treated. Examples of   meta-fields include the document’s _index, _type, _id, and _source fields.2、Fields or properties  A mapping type contains a list of fields or properties pertinent to the documen

 映射類型

    每個索引會有一種決定他如何被索引的映射類型

    【6.0.0】中棄用, 查詢棄用的映射類型

    映射的類型有:

    1、原域:原域被用來定義如何處理文檔中的中繼資料,原域包括文檔索引、類型、_id欄位和_source域

    2、域或屬性:映射類型包含文檔相關的域或屬性的列表

 

Field datatypeseditEach field has a data type which can be:1、a simple type like text, keyword, date, long, double, boolean or ip.2、a type which supports the hierarchical nature of JSON such as object or nested.
3、or a specialised type like geo_point, geo_shape, or completion.
It is often useful to index the same field in different ways for different purposes. For instance, a
string field could be indexed as a text field for full-text search, and as a keyword field for sorting or
aggregations. Alternatively, you could index a string field with the standard analyzer, the english analyzer, and the french analyzer.This is the purpose of multi-fields. Most datatypes support multi-fields via the fields parameter.

  域的資料類型

    每個域都有一個資料類型,功能如下:

    1、簡單類型如text(預設分詞還有一個不分詞的.keywork)、keyword、date、long、double、boolean、ip

    2、支援json分層性質的object或nested(嵌套的實體可以獨立被搜尋)

    3、還有比較專業的geo_point, geo_shape, 和 completion類型

  為了不同的目的,用不同的方法索引相同的欄位通常是有用的。例如,可以將字串欄位索引為全文檢索搜尋的文字欄位,並作為排序或彙總的關鍵字欄位。或者,也可以使用標準分析器、英語分析器和法語分析器對字串欄位進行索引。

  這是多領域的目的。大多數資料類型通過欄位參數支援多欄位。

  

Settings to prevent mappings explosione
Defining too many fields in an index is a condition that can lead to a mapping explosion, which can cause out of memory errors and
difficult situations to recover from. This problem may be more common than expected. As an example, consider a situation in which every new
document inserted introduces new fields. This is quite common with dynamic mappings. Every time a document contains new fields, those will end
up in the index’s mappings. This isn’t worrying for a small amount of data, but it can become a problem as the mapping grows. The following settings
allow you to limit the number of field mappings that can be created manually or dynamically, in order to prevent bad documents from causing a mapping
explosion:

index.mapping.total_fields.limit
  The maximum number of fields in an index. The default value is 1000.
index.mapping.depth.limit
  
The maximum depth for a field, which is measured as the number of inner objects. For instance, if all fields are defined at the root object level,
then the depth is 1. If there is one object mapping, then the depth is 2, etc. The default is 20.
index.mapping.nested_fields.limit
  
The maximum number of nested fields in an index, defaults to 50. Indexing 1 document with 100 nested fields actually indexes 101 documents as each
nested document is indexed as a separate hidden document.

  防止映射爆炸

    在索引中定義太多欄位會導致映射爆炸,這可能導致記憶體錯誤和難以恢複的情況。這個問題可能比預期的更普遍。例如,考慮一種情況,其中插入的每個新文檔都引入了新欄位。這在動態映射中非常常見。每當文檔包含新欄位時會結束索引的映射。對於少量資料來說,這並不令人擔心,但隨著映射的增長,這可能成為一個問題。以下設定允許您限制自動或手動產生fiel的數量,防止映射explosin破壞文檔:

  index.mapping.total_fields.limit:索引中欄位的最大數量。預設值是1000

  index.mapping.depth.limit:一個欄位的最大深度,它被測量為內部對象的數量。例如,如果所有欄位都在根對象層級定義,那麼深度為1。如果有一個對象映射,那麼深度是2,等等。預設值是20。

  index.mapping.nested_fields.limit:索引中嵌套欄位的最大數量,預設為50。索引一個包含100個嵌套欄位的文檔實際上索引了101個文檔,因為每個嵌套的文檔被索引為一個單獨的隱藏文檔。

Dynamic mappingeditFields and mapping types do not need to be defined before being used. Thanks to dynamic mapping, new field names will be added automatically, just by indexing a document. New fields can be added both to the top-level mapping type, and to inner object and nested fields.The dynamic mapping rules can be configured to customise the mapping that is used for new fields.Explicit mappingseditYou know more about your data than Elasticsearch can guess, so while dynamic mapping can be useful to get started, at some point you will want to specify your own explicit mappings.You can create field mappings when you create an index, and you can add fields to an existing index with the PUT mapping API.
View Code

  動態映射:

    欄位和映射類型在使用之前不需要定義。由於動態映射,,只需對文檔進行索引就將自動添加新的欄位名。可以將新欄位添加到頂級映射類型和內部對象和嵌套欄位中。

    動態映射規則可以為新欄位自訂映射。

  明確映射:

    你對資料的瞭解比elasticsearch更大,因此,雖然動態映射可能很有用,但在某些情況下,需要指定自己的顯式映射。

    你可以在建立索引時建立欄位對應,並且可以使用PUT mapping API將欄位添加到現有索引。

Updating existing field mappingsOther than where documented, existing field mappings cannot be updated. Changing the mapping would mean invalidating already indexed documents. Instead, you should create a new index with the correct mappings and reindex your data into that index.
View Code

  更新現有欄位對應

    除了文檔記錄之外,不能更新現有的欄位對應,改變映射會使原來的索引失效。相反,你應該建立一個新的索引與正確的映射來重建你的索引

Example mappingA mapping could be specified when creating an index, as follows:    建立索引時映射應該被指定PUT my_index {  "mappings": {    "doc": {       "properties": {         "title":    { "type": "text"  },         "name":     { "type": "text"  },         "age":      { "type": "integer" },          "created":  {          "type":   "date",           "format": "strict_date_optional_time||epoch_millis"        }      }    }  }}
View Code

 

Elasticsearch Reference【6.1】Mapping

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.