【问题标题】:Elasticsearch alias and index (same id?)Elasticsearch 别名和索引(相同的 id?)
【发布时间】:2018-07-27 21:38:53
【问题描述】:

我有一个关于 Elasticsearch 的问题。

如果我有 2 个索引 IndexA 和 IndexB。

我将 ID 为“1”的文档 docA 放入 IndexA,并将 ID 为“1”的文档 docB 放入 IndexB。文档的文档类型相同但正文不同(结构相同但值不同)。

如果我创建一个同时指向 IndexA 和 IndexB 的别名“alias1”并执行以下获取请求会发生什么?

response = es_client.get(index="alias1", doc_type="doc_type", id="1")

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    这很容易测试,但简而言之,您不能为使用和别名指向多个索引的文档发出 GET!

    PUT index1/doc/1
    { "test": 1 }
    
    PUT index2/doc/1
    { "test": 2 }
    
    POST _aliases
    {
        "actions" : [
            { "add" : { "index" : "index1", "alias" : "alias1" } },
            { "add" : { "index" : "index2", "alias" : "alias1" } }
        ]
    }
    
    GET alias1/doc/1
    
    =>
    
    {
      "error": {
        "root_cause": [
          {
            "type": "illegal_argument_exception",
            "reason": "Alias [alias1] has more than one indices associated with it [[index2, index1]], can't execute a single index op"
          }
        ],
        "type": "illegal_argument_exception",
        "reason": "Alias [alias1] has more than one indices associated with it [[index2, index1]], can't execute a single index op"
      },
      "status": 400
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多