elasticsearch 6.0.0及之后移除了一个索引允许映射多个类型的操作(Removal of mapping types)

用到了6.2,还以为像5.X 一样允许建立 父-子关系文档 ,即一个索引下允许映射多个类型,操作后发现行不通

如下代码:

PUT /company
{
  "mappings": {
    "branch": {},
    "employee": {
      "_parent": {
        "type": "branch"
      }
    }
  }
}

找到最新的官方文档,给出了说明,大意是:

6.0.0移除了一个索引允许映射多个类型,虽然还支持同索引多类型查询,但是Elasticsearch 7.0.0的版本将完全放弃。

不过官方给了另外的方案解决

Custom type fieldedit
Of course, there is a limit to how many primary shards can exist in a cluster so you may not want to waste an entire shard for a collection of only a few thousand documents. In this case, you can implement your own custom type field which will work in a similar way to the old _type.

Let’s take the user/tweet example above. Originally, the workflow would have looked something like this:

PUT twitter
{
  "mappings": {
    "user": {
      "properties": {
        "name": { "type": "text" },
        "user_name": { "type": "keyword" },
        "email": { "type": "keyword" }
      }
    },
    "tweet": {
      "properties": {
        "content": { "type": "text" },
        "user_name": { "type": "keyword" },
        "tweeted_at": { "type": "date" }
      }
    }
  }
}

PUT twitter/user/kimchy
{
  "name": "Shay Banon",
  "user_name": "kimchy",
  "email": "[email protected]"
}

PUT twitter/tweet/1
{
  "user_name": "kimchy",
  "tweeted_at": "2017-10-24T09:00:00Z",
  "content": "Types are going away"
}

GET twitter/tweet/_search
{
  "query": {
    "match": {
      "user_name": "kimchy"
    }
  }
}
You could achieve the same thing by adding a custom type field as follows:

PUT twitter
{
  "mappings": {
    "_doc": {
      "properties": {
        "type": { "type": "keyword" },
        "name": { "type": "text" },
        "user_name": { "type": "keyword" },
        "email": { "type": "keyword" },
        "content": { "type": "text" },
        "tweeted_at": { "type": "date" }
      }
    }
  }
}

PUT twitter/_doc/user-kimchy
{
  "type": "user",
  "name": "Shay Banon",
  "user_name": "kimchy",
  "email": "[email protected]"
}

PUT twitter/_doc/tweet-1
{
  "type": "tweet",
  "user_name": "kimchy",
  "tweeted_at": "2017-10-24T09:00:00Z",
  "content": "Types are going away"
}

GET twitter/_search
{
  "query": {
    "bool": {
      "must": {
        "match": {
          "user_name": "kimchy"
        }
      },
      "filter": {
        "match": {
          "type": "tweet"
        }
      }
    }
  }
}

The explicit type field takes the place of the implicit _type field.

  这是官网的6.x的关于此点的描述:https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

原文地址:https://www.cnblogs.com/liugx/p/8470369.html

时间: 2024-08-30 00:45:36

elasticsearch 6.0.0及之后移除了一个索引允许映射多个类型的操作(Removal of mapping types)的相关文章

(译)MySQL 8.0实验室---MySQL中的倒叙索引(Descending Indexes)

译者注:MySQL 8.0之前,不管是否指定索引建的排序方式,都会忽略创建索引时候指定的排序方式(语法上不会报错),最终都会创建为ASC方式的索引,在执行查询的时候,只存在forwarded(正向)方式对索引进行扫描.关于正向索引和反向索引,逻辑上很容易理解,这里有两个相关的概念:正向索引或者反向索引,两者都是在构建B树索引时候的相关字段排序方式,是B索引树的逻辑存储方式正向扫描(forward)和反向扫描( Backward index scan;)是执行查询的过程中对B树索引的扫描方式,是数

Elasticsearch使用java读取数据报错NoNodeAvailableException: None of the configured nodes are available: [127.0.0.1:9300]

对于这个问题,大部分人出现在这个地方: Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("172.16.2.13", 9300));? 问题在于前面初始化settings时给cluster设置了个新的名字,如:Settings settings = ImmutableSettings.settingsBuilder().put("c

ElasticSearch 5.0.0 安装部署常见错误或问题

问题一: [2016-11-06T16:27:21,712][WARN ][o.e.b.JNANatives ] unable to install syscall filter: Java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMPandCONFIG_SECCOMP_FILTERcompiledinatorg.elasticsearch.boo

Elasticsearch 2.2.0 精简(cat)API

在Elasticsearch提供了一套精简API来查看系统的状态,官方的文档叫cat API.主要的目的是由于Elasticsearch默认提供的接口返回都是JSON格式的,这种格式不利于人类的阅读,所以搞出来一套cat API来简化. 每个命令都是以/_cat开头,可以接收v参数得到详细输出:可以通过help参数得到返回的每列的帮助信息.可以通h=参数名返回部分内容,多个参数可以用逗号分开,甚至可以支持通配符.例如: 请求:GET http://127.0.0.1:9200/_cat/mast

Elasticsearch 2.2.0 分词篇:中文分词

在Elasticsearch中,内置了很多分词器(analyzers),但默认的分词器对中文的支持都不是太好.所以需要单独安装插件来支持,比较常用的是中科院 ICTCLAS的smartcn和IKAnanlyzer效果还是不错的,但是目前IKAnanlyzer还不支持最新的Elasticsearch2.2.0版本,但是smartcn中文分词器默认官方支持,它提供了一个中文或混合中文英文文本的分析器.支持最新的2.2.0版本版本.但是smartcn不支持自定义词库,作为测试可先用一下.后面的部分介绍

Elasticsearch 2.2.0 JAVA开发篇:搜索操作

普通查询 Elasticsearch java API同时提供了强大的搜索功能,不过这也是很正常的因为所有的http接口到后面都要转换成java代码才可以执行.索引名和type名称都可以是多个,用逗号分开. SearchRequestBuilder  sbuilder = client.prepareSearch("secilog") //index name .setTypes( "type") //type name .setSearchType(SearchT

elk(Elasticsearch 2.0.0, Logstash 2.0.0, Kibana4.2.0) redis centos6.6安装与配置

本次安装的相关环境:Centos_x64_6.6  redis2.8.23  Elasticsearch 2.0.0, Logstash 2.0.0,  Kibana4.2.0 软件下载地址: redis: http://redis.io/download Elasticsearch: wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticse

Windows下安装Elasticsearch 5.0.0遇到的问题

首先用一种比较简单的方法 首先下载zip安装包:https://www.elastic.co/downloads/elasticsearch . 解压到安装目录: 进入安装目录,在进入bin目录,启动cmd: 运行elasticsearch.bat.报错Unsupported major.minor version 52.0. 原因是我同时安装了jdk1.7和jdk1.8.但是环境变量中我的JAVA_HOME设置的是jdk1.7的,Elasticsearch 5.0.0只支持jdk1.8,所以启

【拆分版】Docker-compose构建Elasticsearch 7.1.0集群

写在前边 搞了两三天了,一直有个问题困扰着我,ES集群中配置怎么能正确映射到主机上,这边经常报ClusterFormationFailureHelper master not discovered or elected yet.原因是容器中的ES节点没有正确的映射到主机上,而且容器内ip是易变的,我该怎么配置呢? 临下班了,终于想到个法子,固定容器ip--使用network_mode: host 看到主机模式的我眼前一亮,容器就相当于一个主机服务,你占哪个端口就是哪个,没有必要再去自己指定por