elasticsearch 弹性搜索路由突然失效
我的弹性6.8和路由似乎不工作。我举的例子
elasticsearch 弹性搜索路由突然失效,
elasticsearch,
elasticsearch,我的弹性6.8和路由似乎不工作。我举的例子 PUT my_index/_doc/2?routing="user1" { "title": "This is a document" } { "_index" : "my_index", "_type" : "_doc", "_id" : "2",
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
query时
GET my_index/_doc/2?routing="user1"
没有结果。看起来很奇怪,我是不是遗漏了什么
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "2",
"found" : false
}
更新#1
以下API导致错误(取自文档)
由于在
PUT my_index/\u doc/1?routing=user1&refresh=true
中的refresh=true
末尾添加了1或2个空格字符,因此出现以下错误
{
"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
}
使用检索文档时
GEThttp://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"
}
}
在传递路由字段时,刷新是否为强制属性?p请检查是否通过路由字段而不通过refresh@Nag
refresh
在传递路由字段时不是强制属性。甚至您也不应该在每个索引操作中添加?refresh=true
,因为它会降低索引速度。@Nagrefresh
的添加是为了在操作发生后立即刷新相关的主碎片和副本碎片(而不是整个索引),以便更新后的文档立即出现在搜索结果中。请浏览此文档以了解有关?刷新@Nag的更多信息如果有助于您解决问题,请不要忘记投票并接受我的答案:)这是真的,但我想知道为什么查询没有返回结果(来自我最初发布的问题)
{
"_index": "64762507",
"_type": "_doc",
"_id": "1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"_routing": "user1",
"found": true,
"_source": {
"name": "multi grain bread"
}
}