elasticsearch,mapping,Types,elasticsearch,Mapping" /> elasticsearch,mapping,Types,elasticsearch,Mapping" />

Types 多类型弹性搜索的映射

Types 多类型弹性搜索的映射,types,elasticsearch,mapping,Types,elasticsearch,Mapping,我试图为每个数据源创建一个具有多种类型的索引 以下映射不会为一种类型创建映射: curl -XPUT localhost:9200/test -d '{ "settings" : { "number_of_shards" : 1 }, "mappings" : { "type1" : { "_source" : { "enabled" : false }, "properties" : {

我试图为每个数据源创建一个具有多种类型的索引

以下映射不会为一种类型创建映射:

curl -XPUT localhost:9200/test -d '{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "type1" : {
            "_source" : { "enabled" : false },
            "properties" : {
                "field1" : { "type" : "string", "index" : "not_analyzed" }
            }
        }
    },
    "mappings" : {
        "type2" : {
            "_source" : { "enabled" : false },
            "properties" : {
                "source1" : { "type" : "string", "index" : "not_analyzed" }
            }
        }
    }
}'
当我运行此命令时:

curl -X GET 'http://localhost:9200/test/tpe1/_mapping?pretty=true'
没有显示任何内容


如何在弹性搜索中为多个类型创建映射?

虽然可能有一种方法可以在单个调用中实现这一点,但在多个调用中实现这一点同样容易,从而使事情更加独立

PUT hilden1

PUT hilden1/type1/_mapping
{
  "properties": {
    "value1": {
      "type": "string"
    }
  }
}

PUT hilden1/type2/_mapping
{
  "properties": {
    "value2": {
      "type": "string"
    }
  }
}


GET hilden1/_mapping

在2个调用上设置映射还有一个额外的好处,即不影响同一索引中的第3种类型。

首先,您将映射应用于弹性搜索

curl -XPUT localhost:9200/index/_setting -d @indexsetting.json
为Type1和Type2映射创建一个两个json文件 Mapping1.json:

{
"type1":{
"properties" : {
 "field1" : { "type" : "string", "index" : "not_analyzed" } 
}}} 
Mapping2.json

{
"type2":{
"properties" : {
 "field1" : { "type" : "string", "index" : "not_analyzed" } 
}}} 
然后,您将逐个执行下面的查询

curl -XPUT localhost:9200/index/type1/_mapping -d @mapping1.json
curl -XPUT localhost:9200/index/type2/_mapping -d @mapping2.json
这是在弹性搜索中创建索引和映射的正确方法