【问题标题】:Mapping for a elastic search with multiple types映射具有多种类型的弹性搜索
【发布时间】:2023-04-03 06:23:01
【问题描述】:

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

以下映射确实为一种类型创建映射:

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'

什么都不显示。

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

【问题讨论】:

    标签: types elasticsearch mapping


    【解决方案1】:

    虽然可能有一种方法可以在单个调用中执行此操作,但在多个调用中执行此操作同样容易,从而使事情更加独立。

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

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

    【讨论】:

      【解决方案2】:

      首先,您将映射应用到 Elastic 搜索

      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
      

      这是在弹性搜索中创建索引和映射的正确方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-15
        • 2012-03-04
        • 1970-01-01
        相关资源
        最近更新 更多