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
    }
    
  • 相关阅读:
    聊聊es6中的解构
    JavaScript 中的面向对象编程
    TypeScript 中的类型保护
    7个你应该知道的 JavaScript 原生错误类型
    使用JavaScript策略模式校验表单
    nodejs如何解决高并发?
    nodejs核心模块有哪些?
    Dungeon Master
    Gold Balanced Lineup
    poj 2513Colored Sticks
  • 原文地址:https://www.cnblogs.com/xing901022/p/5308950.html
Copyright © 2011-2022 走看看