ElasticSearch路由没有突然工作

ma8fv8wu  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(1)|浏览(355)

我是弹性6.8和路由似乎不工作。我用的例子,

PUT my_index/_doc/2?routing="user1" 
{
  "title": "This is a document"
}

{
  "_index" : "my_index",
  "_type" : "_doc",
  "_id" : "2",
  "_version" : 2,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}

关于申请 GET 查询

GET my_index/_doc/2?routing="user1"

没有结果。看起来很奇怪,我是不是遗漏了什么?

{
  "_index" : "my_index",
  "_type" : "_doc",
  "_id" : "2",
  "found" : false
}

更新#1
以下api导致错误(取自文档)

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

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Unknown value for refresh: [true ]."
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Unknown value for refresh: [true ]."
  },
  "status": 400
}
33qvvth1

33qvvth11#

出现以下错误是因为在结尾处添加了1或2个空格字符 refresh=truePUT my_index/_doc/1?routing=user1&refresh=true ```
{
"type": "illegal_argument_exception",
"reason": "Unknown value for refresh: [true ]."
}

来自elasticsearch源代码:

if ("".equals(value)) {
// Empty string is IMMEDIATE because that makes "POST /test/test/1?refresh" perform
// a refresh which reads well and is what folks are used to.
return IMMEDIATE;
}
throw new IllegalArgumentException("Unknown value for refresh: [" + value + "].");

删除结尾的空白,然后再次尝试索引文档
添加工作示例:
索引数据:

PUT http://localhost:9200/{{index-name}}/_doc/1?routing=user1&refresh=true

{
"name":"multi grain bread"
}

作为回应,你会得到

{
"_index": "64762507",
"_type": "_doc",
"_id": "1",
"_version": 1,
"result": "created",
"forced_refresh": true,
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}

使用检索文档时 `GET http://localhost:9200/{{index-name}}/_doc/1?routing=user1` 作为回应,您将得到:

{
"_index": "64762507",
"_type": "_doc",
"_id": "1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"_routing": "user1",
"found": true,
"_source": {
"name": "multi grain bread"
}
}

相关问题