再次学习ES--10--6.4Mapping

2018-12-06  本文已影响0人  lionel880

1.ES6.4支持的 field type

参考文档:【https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html

2.字段类型有哪些支持的属性

doc_values和fielddata,重点理解

Most fields are indexed by default, which makes them searchable. 
The inverted index allows queries to look up the search term 
in unique sorted list of terms, 
and from that immediately have access to the list of documents that contain the term.

Sorting, aggregations, and access to field values in scripts 
requires a different data access pattern.
 Instead of looking up the term and finding documents, 
we need to be able to look up the document and find the terms that it has in a field.

Doc values are the on-disk data structure,
 built at document index time, which makes this data access pattern possible. 
They store the same values as the _source but in a column-oriented fashion
 that is way more efficient for sorting and aggregations. 
Doc values are supported on almost all field types,
 with the notable exception of analyzed string fields.

为了准确理解,粘贴英文原文。
大部分字段都是为了可以搜索,都是默认索引的,倒排索引的结构使得查询包含某些term的文档非常高校,但涉及排序,聚合和脚本等,这个倒排索引效率就不行了,需要另外一种数据结构。
Doc Value是存储在硬盘上的数据结构,在索引期间创建,存贮的数据和_source一样,但是 column-oriented 形式的,这使得排序和聚合更为高效。

相反,text字段使用称为查询时的内存中数据结构 fielddata。第一次将字段用于聚合,排序或脚本时,此数据结构是根据需要构建的。它是通过从磁盘读取每个段的整个反向索引,反转术语↔︎文档关系,并将结果存储在内存中的JVM堆中构建的。

text默认情况下,在字段上禁用Fielddata 编辑
Fielddata可能会消耗大量的堆空间,尤其是在加载高基数text字段时。一旦fielddata已加载到堆中,它将在该段的生命周期内保留。此外,加载fielddata是一个昂贵的过程,可能会导致用户遇到延迟命中

Multi-fields

为不同目的以不同方式索引相同字段通常很有用。例如,string可以将字段映射为text用于全文搜索的keyword字段,
以及用于排序或聚合的字段。或者,您可以使用standard分析仪, english分析仪和 french分析仪索引文本字段。
这是多领域的目的。大多数数据类型都通过fields参数支持多字段。

这里只需要注意fields这个的语法即可,得取个名字分别进行使用

3.有哪些注意点

OBJECT

{
  "title":            [ eggs, nest ],
  "body":             [ making, money, work, your ],
  "tags":             [ cash, shares ],
  "comments.name":    [ alice, john, smith, white ],
  "comments.comment": [ article, great, like, more, please, this ],
  "comments.age":     [ 28, 31 ],
  "comments.stars":   [ 4, 5 ],
  "comments.date":    [ 2014-09-01, 2014-10-22 ]
}

NESTED

{ 
  "comments.name":    [ john, smith ],
  "comments.comment": [ article, great ],
  "comments.age":     [ 28 ],
  "comments.stars":   [ 4 ],
  "comments.date":    [ 2014-09-01 ]
}
{ 
  "comments.name":    [ alice, white ],
  "comments.comment": [ like, more, please, this ],
  "comments.age":     [ 31 ],
  "comments.stars":   [ 5 ],
  "comments.date":    [ 2014-10-22 ]
}
连接字段不应像关系数据库中的连接一样使用。
在Elasticsearch中,良好性能的关键是将数据去规范化为文档。每个联接字段has_child或has_parent查询都会为查询性能添加重要税。

连接字段有意义的唯一情况是,如果您的数据包含一对多关系,
其中一个实体明显超过另一个实体。这种情况的一个例子是产品的用例和这些产品的报价。
如果提供的产品数量明显多于产品数量,则将产品建模为父文档并将产品建模为子文档是有意义的。

实际情况下,往往通过增加数据冗余来完成,具体的效率还是需要进行评估的

上一篇 下一篇

猜你喜欢

热点阅读