zoukankan      html  css  js  c++  java
  • 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
    }
    
  • 相关阅读:
    微信报警提示
    使用pygal图表显示网站API接口数据
    读写文本文件,乱码解决方案
    MD5加密
    将DataTable导入到SQL数据库表中
    NPOI组件操作Excel导入、导出
    二叉树由先序和中序建树
    用两个栈模拟队列
    math type白嫖教程
    IDEA常用快捷键
  • 原文地址:https://www.cnblogs.com/xing901022/p/5308950.html
Copyright © 2011-2022 走看看