ES学习之路 -- Mapping是什么?

304 阅读1分钟

自动或手动为index中的type建立的一种数据结构和相关配置,简称为mapping 查看当前index/type的mapping结构的命令:

GET /website/article/mapping

mapping 只能在新建index时创建,或者添加新的field mapping,并不能够修改已有的mapping 手动建立mapping:

PUT /website
{
  "mappings": {
    "article":{
      "properties": {
        "author_id":{
          "type": "long"
        },
        "title":{
          "type": "text",
          "analyzer": "english"
        },
        "content":{
          "type": "text"
        },
        "post_date":{
          "type": "date"
        }
      }
    }
  }
}

添加新field mapping:

PUT /website/_mapping/article
{
  "properties": {
    "tags":{
      "type": "text"
    }
  }
}

根据mapping中的字段分词器:

GET /website/_analyze
{
  "field": "second_field",
  "text": "my dog"
}