Elasticsearch——禁止Body中的index覆盖Url中的index参数

本篇继续一下Elasticsearch日常使用的技巧翻译。

在Elasticsearch有很多的api支持在body中指定_index等信息,比如mget或者msearch以及bulk。

默认的情况下,body中的index会覆盖掉url中的index参数。比如:

$ curl localhost:9200/test/_mget?pretty -d '{"docs":[{"_index":"test1","_id":1},{"_index":"test2","_id":2}]}'
{
  "docs" : [ {
    "_index" : "test1",
    "_type" : "tet",
    "_id" : "1",
    "_version" : 2,
    "found" : true,
    "_source":{"name":"1"}
  }, {
    "_index" : "test2",
    "_type" : null,
    "_id" : "2",
    "found" : false
  } ]
}

虽说在url中指定了index为test,但是执行到每个文档时,仍然会按照body里面的内容为准。

此时可以通过设置参数rest.action.multi.allow_explicit_indexfalse来关闭覆盖功能。

这个设置会对所有的节点起作用,设置方法如下:

config/elasticsearch.yml中添加:

rest.action.multi.allow_explicit_index: false

然后重启Elasticsearch,再次执行就会发现,服务器已经提示拒绝。

$ curl localhost:9200/test/_mget?pretty -d '{"docs":[{"_index":"test1","_id":1},{"_index":"test2","_id":2}]}'
{
  "error" : "ElasticsearchIllegalArgumentException[explicit index in multi get is not allowed]",
  "status" : 400
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值