【问题标题】:Correctly folding ASCII characters in Elasticsearch在 Elasticsearch 中正确折叠 ASCII 字符
【发布时间】:2016-04-22 09:17:12
【问题描述】:

我正在研究支持折叠非标准 ASCII 字符,例如 this guide 建议。

PUT /my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "folding": {
          "tokenizer": "standard",
          "filter":  [ "lowercase", "asciifolding" ]
        }
      }
    }
  }
}

奇怪的是,我无法在代码的第一个 sn-p 中复制示例。

当我执行时

GET /my_index/_analyze?analyzer=folding&text=My œsophagus caused a débâcle

返回以下标记:

sophagus, caused, a, d, b, cle

我想要实现的是:

“école”等单词的拼写变体(例如,ecole、ècole)应视为同一个单词。

现在,如果我执行

GET /my_index/_analyze?analyzer=folding&text=école ecole

我得到令牌cole, ecole

这些是我目前用于文档文本分析的设置

    "analysis": {
  "filter": {
    "french_stop": {
      "type": "stop",
        "stopwords": "_french_"
    },
      "french_elision": {
        "type": "elision",
          "articles": [
            "l",
            "m",
            "t",
            "qu",
            "n",
            "s",
            "j",
            "d",
            "c",
            "jusqu",
            "quoiqu",
            "lorsqu",
            "puisqu"
          ]
      },
        "french_stemmer": {
          "type": "stemmer",
            "language": "light_french"
        }
  },
    "analyzer": {
      "index_French": {
        "filter": [
          "french_elision",
          "lowercase",
          "french_stop",
          "french_stemmer"
        ],
          "char_filter": [
            "html_strip"
          ],
            "type": "custom",
              "tokenizer": "standard"
      },
        "sort_analyzer": {
          "type": "custom",
            "filter": [
              "lowercase"
            ],
              "tokenizer": "keyword"
        }
    }
}

我的想法是更改 index_French 分析器的过滤器,以便列表如下:

"filter": ["french_elision","lowercase","asciifolding","french_stop","french_stemmer"]

感谢您的帮助。

【问题讨论】:

  • 你显然需要使用asciifolding 令牌过滤器,试试看,你会看到。
  • 如果你指的是更大的分析仪,你是对的。但我无法使用我链接的文档页面中的小样本进行正确折叠。
  • 我刚试过,效果很好。你可以试试这个吗? curl -XGET 'localhost:9200/my_index/_analyze?analyzer=folding&pretty' -d 'My œsophagus caused a débâcle'
  • 好吧奇怪的事情:如果我在 Sense 中运行,我会遇到同样的问题。如果我使用 Powershell,我会收到 my, oesophagus, caused, a, debacle... 我错过了将集群指定为 Amazon Elasticsearch Service 域。命令:(iwr -Uri "http://xxxxxxx/my_index/_analyze?analyzer=folding&pretty&text=My œsophagus caused a débâcle").Content

标签: elasticsearch text-analysis


【解决方案1】:

在 Sense 中,您需要像这样调用 _analyze 端点,它会起作用:

POST /foldings/_analyze
{
   "text": "My œsophagus caused a débâcle",
   "analyzer": "folding"
}

你会得到

{
   "tokens": [
      {
         "token": "my",
         "start_offset": 0,
         "end_offset": 2,
         "type": "<ALPHANUM>",
         "position": 0
      },
      {
         "token": "oesophagus",
         "start_offset": 3,
         "end_offset": 12,
         "type": "<ALPHANUM>",
         "position": 1
      },
      {
         "token": "caused",
         "start_offset": 13,
         "end_offset": 19,
         "type": "<ALPHANUM>",
         "position": 2
      },
      {
         "token": "a",
         "start_offset": 20,
         "end_offset": 21,
         "type": "<ALPHANUM>",
         "position": 3
      },
      {
         "token": "debacle",
         "start_offset": 22,
         "end_offset": 29,
         "type": "<ALPHANUM>",
         "position": 4
      }
   ]
}

【讨论】:

  • 好吧,我现在觉得自己很蠢。我得到了一个奇怪的回应:它在标记列表中包含“分析器”、“折叠”和“文本”。 pastebin.com/6qHDZhK5
  • 好的,我认为您正在测试 ES 1.x,而我正在使用 ES 2.x 进行测试,POST _analyze 仅在 ES 2.x 及更高版本中受支持,但请尝试使用 curl,它会两者都工作
  • 是的。 AWS 在 1.5 上运行... Powershell 上的 iwr 工作正常。有区别的原因吗?
  • 可能是因为 Sense 发送/编码查询的方式
  • 很高兴我们知道了!
猜你喜欢
  • 2012-11-28
  • 2019-09-13
  • 2011-11-25
  • 2012-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-21
  • 2021-06-08
相关资源
最近更新 更多