elasticsearch:单个索引中的多种类型

问题描述 投票:0回答:2

我正在尝试在单个索引中创建多种类型。例如,我尝试在

host
索引中创建两种类型 (
post
,
ytb
),以便在它们之间创建父子关系。

PUT /ytb
{
  "mappings": {
      "post": {
          "_parent": {
              "type": "host" 
            },
          "properties":{
            "@timestamp": {
                  "type": "date"
              },
            "indexed": {
                  "type": "date"
              },
              "n_comments": {
                  "type": "long"
              }, 
              "n_harvested": {
                  "type": "long"
              }, 
              "n_likes": {
                  "type": "long"
              },
              "network": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              },
              "parent_id": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "post_dbid": {
                  "type": "long"
              }, 
              "post_id": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "post_netid": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "published": {
                  "type": "date"
              }
          }
      },
      "host": {
          "properties": {
              "@timestamp": {
                  "type": "date"
              }, 
              "@version": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "country": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "host_dbid": {
                  "type": "long"
              }, 
              "host_id": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "host_netid": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "id": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "indexed": {
                  "type": "date"
              }, 
              "language": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              },
              "name": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }, 
              "vertical": {
                  "fields": {
                      "keyword": {
                          "ignore_above": 256, 
                          "type": "keyword"
                      }
                  }, 
                  "type": "text"
              }
          }
      }
  }
}

但我收到此错误:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [ytb] as the final mapping would have more than 1 type: [post, host]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Rejecting mapping update to [ytb] as the final mapping would have more than 1 type: [post, host]"
  },
  "status": 400
}

更新:Elasticsearch 版本:6.3.0

elasticsearch
2个回答
12
投票

如果您有 ES 5.6 或更高版本,则需要阅读本文。总而言之,从 ES 6 开始,映射类型将被删除,每个索引只有一种类型将成为标准。

为了回答您在评论中的问题,我知道另一个类似 Kibana 的工具(实际上是 Kibana 分支),它知道如何处理 JOIN 和关系数据。 Siren Solutions 将其称为“Kibi”。另请阅读博客公告

更新:

Kibi项目似乎不再维护了。 如果您现在想做 JOIN,您可能需要花一些时间学习新的

ES|QL 语言

,它允许您进行搜索时丰富(与 JOIN 非常相似)


1
投票
https://www.elastic.co/guide/en/elasticsearch/reference/6.1/removal-of-types.html

总结一下:

原因:同一个索引中的不同类型不是独立的。这些类型中的公共字段应该具有相同的数据类型,因为它们内部由相同的 Lucene 字段支持。
  • 缺点:公共字段较少的两种类型会导致数据存储稀疏。
  • 解决方法:定义一个具有两种类型中所有字段的自定义类型,使用自定义
  • type
  • (或类似的东西),并使用自定义
    type
    字段进行 CRUD。
    
        
© www.soinside.com 2019 - 2024. All rights reserved.