elasticsearch创建索引 ,mapping,dynamic_templates

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: elasticsearch 创建索引时通常需要配置mapping。mapping的含义类似于关系数据库中的表结构。但mapping更加灵活。

简述

elasticsearch 创建索引时通常需要配置mapping。mapping的含义类似于关系数据库中的表结构。但mapping更加灵活。

创建

以下实例是创建索引:my-index-000001,并加入dynamic_templates。
地址
http://localhost:9400/my-index-000001
方式
put
端口
http 端口
模板内容

{
  "mappings": {
    "_default_": {
     "dynamic_templates": [
          {
            "string_fields": {
              "match": "*",
              "match_mapping_type": "string",
              "mapping": {
                "analyzer": "ik_max_word",
                "fields": {
                  "raw": {
                    "ignore_above": 2000,
                    "type": "keyword"
                  }
                },
                "index": "true",
                "omit_norms": true,
                "type": "text"
              }
            }
          }
        ],
          "properties": {
                    "amount": {
                        "type": "double"
                       
                    }
          }
    }
  }
}

curl 方式

curl --location --request PUT 'http://localhost:9400/my-index-000001' \
--header 'Content-Type: application/json' \
--data-raw '{
  "mappings": {
    "_default_": {
     "dynamic_templates": [
          {
            "string_fields": {
              "match": "*",
              "match_mapping_type": "string",
              "mapping": {
                "analyzer": "ik_max_word",
                "fields": {
                  "raw": {
                    "ignore_above": 2000,
                    "type": "keyword"
                  }
                },
                "index": "true",
                "omit_norms": true,
                "type": "text"
              }
            }
          }
        ],
          "properties": {
                    "contract_amount": {
                        "type": "double"
                        
                    }
          }
    }
  }
}'

总结

上面的模板中配置了 amountdouble 类型。分词器:ik_max_word,查询不分词的属性:raw

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
21天前
|
存储 自然语言处理 关系型数据库
ElasticSearch索引 和MySQL索引那个更高效实用那个更合适
ElasticSearch索引 和MySQL索引那个更高效实用那个更合适
35 0
|
2月前
|
存储 算法 NoSQL
Elasticsearch拆分索引知多少
Elasticsearch拆分索引知多少
31 0
|
3月前
|
数据采集 存储 自然语言处理
elasticsearch 跨索引联合多条件查询
elasticsearch 跨索引联合多条件查询
|
1月前
|
JSON 监控 数据管理
【Elasticsearch专栏 12】深入探索:Elasticsearch使用索引生命周期管理(ILM)自动化删除旧数据
Elasticsearch的ILM功能允许用户定义策略,自动管理索引从创建到删除的生命周期。用户可以设置策略,根据索引年龄或大小自动删除旧数据,节省存储空间。通过应用ILM策略于索引模板,新索引将遵循预定义的生命周期。用户还可以监控ILM状态,确保策略按预期执行。使用ILM,用户可以高效地管理数据,确保旧数据及时删除,同时保持数据完整性和安全性。
|
2月前
|
存储 自然语言处理 搜索推荐
【Elasticsearch专栏 01】深入探索:Elasticsearch的正向索引和倒排索引是什么?
正向索引根据文档ID直接查找文档内容,适用于精确匹配场景;而倒排索引则基于文档内容构建,通过关键词快速定位相关文档,适用于全文搜索,显著提高查询效率,是搜索引擎的核心技术。
|
2月前
|
存储 自然语言处理 搜索推荐
【Elasticsearch专栏 02】深入探索:Elasticsearch为什么使用倒排索引而不是正排索引
倒排索引在搜索引擎中更受欢迎,因为它直接关联文档内容,支持全文搜索和模糊搜索,提高查询效率。其紧凑的结构减少了存储空间,并方便支持多种查询操作。相比之下,正排索引在搜索效率、存储和灵活性方面存在局限。
|
2月前
|
API 索引
Elasticsearch Index Shard Allocation 索引分片分配策略
Elasticsearch Index Shard Allocation 索引分片分配策略
76 1
|
2月前
|
存储 自然语言处理 关系型数据库
Elasticsearch创建一个索引怎么也这么复杂
Elasticsearch创建一个索引怎么也这么复杂
39 0
|
2月前
|
Java 网络架构 索引
Elasticsearch 如何实现索引的伪·命名空间
Elasticsearch 如何实现索引的伪·命名空间
9 0
|
2月前
|
存储 Java API
在生产环境中部署Elasticsearch:最佳实践和故障排除技巧———索引与数据上传(二)
在生产环境中部署Elasticsearch:最佳实践和故障排除技巧———索引与数据上传(二)

热门文章

最新文章