Mapping 设计指南
- 目录
- 概述
- 需求:
 
- 设计思路
- 实现思路分析
- 1、properties
- 2.fields
 
- 3.search_analyzer
- 4.2、format
- 1、enabled
- 2、doc_values
 
 
- 参考资料和推荐阅读
Survive by day and develop by night.
talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive.
happy for hardess to solve denpendies.
目录

概述
Mapping 设计指南
需求:
最近在使用对应的方法中采用了Mapping 的方法中:ElasticSearch 的 mapping 该如何设计,才能保证检索的高效?
设计思路

实现思路分析
1、properties
mappings、object字段和nested字段包含的子字段就叫做 properties,示例:
PUT my_index
{
  "mappings": {
    "properties": { 
      "manager": {
        "properties": { 
          "age":  { "type": "integer" },
          "name": { "type": "text"  }
        }
      },
      "employees": {
        "type": "nested",
        "properties": { 
          "age":  { "type": "integer" },
          "name": { "type": "text"  }
        }
      }
    }
  }
}
2.fields
对同一个字段建立不同的索引方式,即multi-field。示例:
```java
PUT my_index
{
  "mappings": {
    "properties": {
      "name": { 
       # 针对 name 字段,使用 standard 分词器建立索引
        "type": "text",
        "fields": {
       # 针对 name.sub_name 字段,使用 english 分词器建立索引
          "sub_name": { 
            "type":     "text",
            "analyzer": "english"
          }
        }
      }
    }
  }
}
2、analyzer
设置text类型字段index时的分词器。如上例中的【"analyzer": "english"】,就表示对 name.sub_name 字段,使用 english 分词器建立索引。
关于analyzer,方才兄在这里补充一个知识点,ElasticSearch如何确定 index 的 analyzer:
```java
PUT my_index
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "whitespace"
      }
    }
  }
}
# 指定字段 title 建立倒排索引时的 analyzer 为 whitespace
3.search_analyzer
爬虫调度器就是可以利用多线程机制,进行调度似的更快的进行网页爬取。
 设置 search 时使用的分词器。ElasticSearch 如何确定 search 时的 analyzer:
GET my_index/_search
{
  "query": {
    "match": {
      "message": {
        "query": "Quick foxes",
        "analyzer": "stop"
      }
    }
  }
}
2)读取 index 的 mapping 字段配置 search_analyzer
PUT my_index
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "whitespace",
        "search_analyzer": "simple"
      }
    }
  }
}
4.2、format
这个也比较简单,就是对网页元素进行解析,通常利用JSONP,xpath等技术进行网页分析。
ES的date类型允许我们规定格式,可以使用的格式有3种:
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd
epoch_millis(毫秒值)
 
# 规定格式如下:|| 表示或者
 
PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "date": {
          "type":   "date",
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        }
      }
    }
  }
}
注意:一旦我们规定了格式,如果新增数据不符合这个格式,ES将会报错mapper_parsing_exception。
1、enabled
设置成 false,仅做存储,不⽀持搜索和聚合分析 (数据保存在 _source 中)。
2、doc_values
参考资料和推荐阅读
参考资料
 官方文档
 开源社区
 博客文章
 书籍推荐
- https://blog.csdn.net/qq_36095679/article/details/109376980
欢迎阅读,各位老铁,如果对你有帮助,点个赞加个关注呗!同时,期望各位大佬的批评指正~






![[C国演义] 第十五章](https://img-blog.csdnimg.cn/13be8dae6e4e4a98950ed27ad7e90a23.png)












