elasticsearch 路由不起作用(官方文档示例)

tzxcd3kk  于 2022-12-26  发布在  ElasticSearch
关注(0)|答案(1)|浏览(143)

作为第一步,我创建了一个包含2个分片和路由的有效索引:

PUT my-index-000001
{
  "settings":
  {
    "index.number_of_shards": 2
  },
  "mappings": {
    "_routing": {
      "required": true 
    }
  }
}

以下官方文档我使用的样本提供那里:

PUT my-index-000001/_doc/1?routing=user1&refresh=true 
{
  "title": "This is a document"
}

GET my-index-000001/_doc/1?routing=user1

以上显然工作-什么是不工作的是,当我改变路由值为user2,它仍然得到我相同的文档,但它不应该,因为它是索引到路由user1(不同的碎片)-我错过了什么?

GET my-index-000001/_doc/1?routing=user2

Result:
{
  "_index": "my-index-000001",
  "_id": "1",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "_routing": "user1",
  "found": true,
  "_source": {
    "title": "This is a document"
  }
}

检索也是如此(我不希望在“user 2”路径上有此文档):

GET my-index-000001/_search?routing=user2
{
  "query":
  {
    "match_all": {}
  }
}

Result:
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "my-index-000001",
        "_id": "1",
        "_score": 1,
        "_routing": "user1",
        "_source": {
          "title": "This is a document"
        }
      }
    ]
  }
}
uwopmtnx

uwopmtnx1#

索引中不能有重复的文档ID
这里,Elasticsearch假设您想用新的路由值更新现有的文档id,这就是为什么您会看到您所看到的内容

相关问题