Elasticsearch:索引mapping

这里写目录标题

一、介绍

二、动态mapping

三、mapping属性

(1)analyzer(分析器)

该analyzer参数指定在索引或搜索字段时用于 文本分析的分析器。text除非使用映射参数覆盖search_analyzer,否则此分析器将用于索引和搜索分析。

  • search_quote_analyzer
    该search_quote_analyzer设置允许您指定短语分析器,这在处理禁用短语查询的停用词时特别有用。要禁用短语的停用词,需要一个利用三个分析器设置的字段:

说明:只有text字段支持analyzer映射参数。

(2) coerce(强制类型转换)

数据不总是干净的.根据它的生成方式,一个数字可能会在 JSON body中呈现为一个真正的 JSON 数字。例如5,但它也可能呈现为字符串,例如 "5" 。或者,应该是整型的数字被替代地呈现为浮点型.例如, 5.0 或者"5.0".

Coercion尝试着清理脏数据让字段符合相应的数据类型.例如 :

  • 字符串被强制转换为数字。
  • 浮点型被截断为整型。

例如:

c 复制代码
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "number_one": {
          "type": "integer"
        },
        "number_two": {
          "type": "integer",
          "coerce": false
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
  "number_one": "10"  # 1
}
'
curl -XPUT 'localhost:9200/my_index/my_type/2?pretty' -H 'Content-Type: application/json' -d'
{
  "number_two": "10"  # 2
}
'
  • number_one 字段会包含整型 10。
  • 由于强制功能已被禁用,因此该文件将被拒绝。

(3)copy_to(合并参数)

copy_to参数允许你创建自定义的 _all 字段.换句换来说,可以将多个字段的值复制到group field(组字段),然后可以作为单个字段进行查询.例如, first_name和 last_name可以复制到 full_name字段中,如下所示 :

c 复制代码
curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "first_name": {
          "type": "text",
          "copy_to": "full_name"  # 1
        },
        "last_name": {
          "type": "text",
          "copy_to": "full_name"  # 2
        },
        "full_name": {
          "type": "text"
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
  "first_name": "John",
  "last_name": "Smith"
}
'
curl -XGET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "full_name": {  # 3
        "query": "John Smith",
        "operator": "and"
      }
    }
  }
}
'
  • 1 , 2 - 》first_name(名字)和 last_name(姓氏)字段复制到full_name 字段。
  • 3 -》first_name(名字)和last_name(姓氏)字段仍然可以分别查询,full_name可以通过first_name(名字)和last_name(姓氏)来查询。

查看数据:

c 复制代码
GET /my_index/my_type/_search
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "my_index",
        "_type": "my_type",
        "_id": "1",
        "_score": 1,
        "_source": {
          "first_name": "John",
          "last_name": "Smith"
        }
      }
    ]
  }
}

一些要点:

  • 复制的是字段值,而不是 term(词条)(由分析过程产生)。
  • _source字段不会被修改来显示复制的值.。
  • 相同的值可以复制到多个字段,通过"copy_to": [ "field_1", "field_2" ] 来操作。
相关推荐
咸鱼求放生1 小时前
es在Linux安装
大数据·elasticsearch·搜索引擎
xyhshen2 小时前
k8s下离线搭建elasticsearch
elasticsearch·容器·kubernetes
人大博士的交易之路3 小时前
今日行情明日机会——20250606
大数据·数学建模·数据挖掘·数据分析·涨停回马枪
Leo.yuan6 小时前
数据库同步是什么意思?数据库架构有哪些?
大数据·数据库·oracle·数据分析·数据库架构
@泽栖6 小时前
ES数据聚合
elasticsearch·搜索引擎
SelectDB技术团队7 小时前
从 ClickHouse、Druid、Kylin 到 Doris:网易云音乐 PB 级实时分析平台降本增效
大数据·数据仓库·clickhouse·kylin·实时分析
Web极客码8 小时前
在WordPress上添加隐私政策页面
大数据·人工智能·wordpress
Apache Flink8 小时前
Flink在B站的大规模云原生实践
大数据·云原生·flink
itachi-uchiha9 小时前
Docker部署Hive大数据组件
大数据·hive·docker
viperrrrrrrrrr710 小时前
大数据学习(131)-Hive数据分析函数总结
大数据·hive·学习