【问题标题】:elasticsearch routing on specific field特定字段上的弹性搜索路由
【发布时间】:2021-04-21 16:28:49
【问题描述】:

您好,我想在我的 Es v2.0 上的特定字段“userId”上设置自定义路由。 但它给了我错误。我不知道如何在 ES v2.0 上设置自定义路由

请大家帮帮我。在此先感谢。以下是错误消息,同时使用现有索引创建自定义路由。

{
  "error": {
     "root_cause": [
       {
          "type": "mapper_parsing_exception",
          "reason": "Mapping definition for [_routing] has unsupported parameters:  [path : userId]"
       }
     ],
   "type": "mapper_parsing_exception",
   "reason": "Mapping definition for [_routing] has unsupported parameters:  [path : userId]"
   },
 "status": 400
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    在 ES 2.0 中,_routing.path 元字段 has been removed。所以现在你需要这样做:

    在您的映射中,您只能指定需要路由(但不能再指定path):

    PUT my_index
    {
      "mappings": {
        "my_type": {
          "_routing": {
            "required": true 
          },
          "properties": {
            "name": {
              "type": "string"
            }
          }
        }
      }
    }
    

    然后当你索引一个文档时,你可以像这样在查询字符串中指定路由值:

    PUT my_index/my_type/1?routing=bar 
    {
      "name": "foo"
    }
    

    【讨论】:

    • 我想在索引中名为 UserId 的字段上路由它。我不想在查询中手动插入路由。
    • 不幸的是,你对 ES 2.x 没有选择,现在就是这样。这主要是做for performance reasons
    • 关于您的问题,您还需要其他什么吗?
    【解决方案2】:

    您仍然可以使用基于被索引数据中的字段的自定义路由。您可以设置一个简单的管道,然后在每次索引文档时使用该管道,或者您也可以更改索引设置以在索引收到文档索引请求时使用该管道。

    了解管道here

    请阅读文档上方和下方以获得更清晰的信息。它不是用于设置自定义路由,但可以用于此目的。自定义路由被禁用的一个很好的原因是,要使用的字段可能会具有导致意外行为的空值。因此,请自行处理该问题。

    对于路由,这里是一个示例管道 PUT:

    PUT localhost:9200/_ingest/pipeline/nameRouting
    Content-Type: application/json
    
    {
      "description" : "Set's the routing value from name field in document",
      "processors" : [
        {
          "set" : {
            "field": "_routing",
            "value": "{{_source.name}}"
          }
        }
      ]
    }
    

    索引设置为:

    {
      "settings" : {
        "index" : {
          "default_pipeline" : "nameRouting"
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 2016-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多