[关闭]
@xtccc 2018-08-04T01:50:29.000000Z 字数 1655 阅读 2119

Indexing, updating, and deleting data

给我写信
GitHub

此处输入图片的描述

ElasticSearch


field的类型


field的类型有三种




关于Mapping


每个文档属于一个type,type属于index。在index新文档时,ES会自动地检测并调整相应type的mapping。

Types contain a definition of each field in the mapping. The mapping includes all the fields that might appear in documents from that type and tells Elasticsearch how to index the fields in a document. Elasticsearch detects your fields automatically and adjusts your mapping accordingly.


获取某个Type已有的mapping

  1. $ curl -XPUT 'ecs1:9200/get-together/new-event/1?pretty' -d '
  2. > {
  3. > "name" : "Last Night With ES",
  4. > "date" : "2015-12-09T14:57"
  5. > }'
  6. 首先向Index一个新的文档(并借此自动地创建相应的type),然后获取该typemapping
  7. $ curl 'ecs1:9200/get-together/new-event/_mapping?pretty'
  8. {
  9. "get-together" : {
  10. "mappings" : {
  11. "new-event" : {
  12. "properties" : {
  13. "date" : {
  14. "type" : "date",
  15. "format" : "dateOptionalTime"
  16. },
  17. "name" : {
  18. "type" : "string"
  19. }
  20. }
  21. }
  22. }
  23. }
  24. }


在创建新的type之前为其定义mapping

下面,我们创建一个名为event-1的type,并为其定义了2个field type,如下:

  1. curl -XPUT 'ecs1:9200/get-together/event-1/_mapping' -d '
  2. > {
  3. > "event-1" : {
  4. > "properties" : {
  5. > "date" : {
  6. > "type" : "date",
  7. > "format" : "dateOptionalTime"
  8. > },
  9. > "name" : {
  10. > "type" : "string"
  11. > }
  12. > }
  13. > }
  14. > }'


合并Mapping

当将一个新的mapping加入到已有的type时,ES会将这两个mapping合并(merge)起来。

新的field会被加入到已有mapping中;
不能改变mapping中已有field的类型


Mapping, indexing 与 analysis

假如某个文档中存在内容"hello world, I am coming with money!"。那么,如果我们的查询内容是"WORLD",这个文档会被查询出来。因为文档内容已经被分析(analyse)过了,具体而言,analyzer通常会对string类型的文档内容进行如下的分析:

  • 将所有的字母转变为小写
  • 将string切分为words
  • 去除停用词

可以在mapping中对analysis相关的选项进行设置

在为某个type创建mapping时,可以对index这个选项进行配置,如下:

该选项有三种值:

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注