【问题标题】:Elasticsearch: how to add language analyser on a field?Elasticsearch:如何在字段上添加语言分析器?
【发布时间】:2018-09-05 21:59:16
【问题描述】:

我有一个法语单词索引。我想对索引属性应用分析器。假设我有一个title 属性,我想将其视为“法国属性”。我试过这个(在 kibana 中):

PUT thing/_mappings/thing
{
  "properties": {
    "title": {
      "type": "text",
      "analyzer": "french",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    }
  }
}

但结果是:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Mapper for [title] conflicts with existing mapping in other types:\n[mapper [title] has different [analyzer]]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Mapper for [title] conflicts with existing mapping in other types:\n[mapper [title] has different [analyzer]]"
  },
  "status": 400
}

我不明白为什么会出现此错误。如果我显示映射 (GET thing/_mappings),它不包含现有的分析器(除非我误解了什么):

 // ...
    "title": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    }
  }

如何将我的 title 财产视为法国财产?(来源:https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-lang-analyzer.html)

【问题讨论】:

  • 您是否还有另一个索引类型为thing?
  • @Val 谢谢你的回答。我对弹性搜索很陌生,有没有办法检查你的要求?
  • 实际上你根本不允许更改title字段的分析器,如果没有指定默认为standard。您需要删除索引并正确更改映射
  • 好的,谢谢!所以,我必须重建所有? (所以删除索引,然后重新发布1G数据?)如果是这样,请随时发表您的评论作为答案,我会接受!

标签: elasticsearch mapping kibana


【解决方案1】:

title字段的分析器是不允许更改的,如果在创建字段时没有指定,默认为standard。

您需要删除索引,更改映射以满足您的需求,然后重新索引您的数据。

另一种解决方案是使用适当的分析器将另一个子字段添加到 title 字段:

PUT thing/_mappings/thing
{
  "properties": {
    "title": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        },
        "french": {                 <--- add this
          "type": "text",
          "analyzer": "french"
        }
      }
    }
  }
}

运行此之后,您无需重新上传所有 1GB 数据,只需调用

POST thing/_update_by_query

为了获取新的子字段。

第二种方法的唯一缺点是,如果您不需要带有standard 分析器的title 字段,那么您最终会得到比需要更多的分析数据。由你决定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-17
    • 1970-01-01
    • 2015-08-06
    • 2015-10-13
    • 1970-01-01
    • 2019-11-15
    • 2016-10-30
    相关资源
    最近更新 更多