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" ] 来操作。
相关推荐
DoveLx2 小时前
如何集成ElasticSearch到Spring Boot+MySQL项目中
java·elasticsearch
yumgpkpm2 小时前
CMP(类ClouderaCDP7.3(404次编译) )完全支持华为鲲鹏Aarch64(ARM),粉丝数超过200就开源下载
hive·hadoop·redis·mongodb·elasticsearch·hbase·big data
Archy_Wang_13 小时前
Elasticsearch8.4.1升级Elasticsearch9.1.5
运维·elasticsearch·jenkins
0和1的舞者4 小时前
《Git:从入门到精通(八)——企业级git开发相关内容》
大数据·开发语言·git·搜索引擎·全文检索·软件工程·初学者
运维行者_5 小时前
AWS云服务故障复盘——从故障中汲取的 IT 运维经验
大数据·linux·运维·服务器·人工智能·云计算·aws
TDengine (老段)5 小时前
TDengine 配置参数作用范围对比
大数据·数据库·物联网·时序数据库·tdengine·涛思数据
武子康6 小时前
大数据-135 ClickHouse 集群连通性自检 + 数据类型避坑实战|10 分钟跑通 ON CLUSTER
大数据·分布式·后端
Olrookie7 小时前
StreamX部署详细步骤
大数据·笔记·flink
CRMEB系统商城8 小时前
【新版发布】标准版PHP v5.6.4正式版,优化部分用户体验
java·大数据·小程序·php·ux