【问题标题】:Elasticsearch asciifolding not working properlyElasticsearch asciifolding 无法正常工作
【发布时间】:2019-12-06 19:05:22
【问题描述】:

我使用 marvel 插件创建了这个测试索引:

POST /test
{
   "index" : {
      "analysis" : {
         "analyzer" : {
            "folding": {
              "tokenizer": "standard",
              "filter":  [ "lowercase", "asciifolding" ]
            }
         }
      }
   }
}

我正在发出这样的分析请求:

GET /test/_analyze?analyzer=folding&text=olá

我得到了结果:

{
    "tokens": [
          {
             "token": "ol",
             "start_offset": 0,
             "end_offset": 2,
             "type": "<ALPHANUM>",
             "position": 1
          }
       ]
}

但我需要一个“ola”令牌而不是“ol”。根据文档,它已正确配置:

https://www.elastic.co/guide/en/elasticsearch/guide/current/asciifolding-token-filter.html

我做错了什么?

【问题讨论】:

  • 这很奇怪,如果我做同样的事情,我会取回令牌“ola”。我刚刚复制了你的命令。
  • 正如您在@user790999 所说的那样,Sense Tool 存在一个错误。应该报告 Sense 开发者。

标签: elasticsearch


【解决方案1】:

试试这个,证明 Elasticsearch 最终做得很好。我怀疑 Sense 接口没有将正确的文本传递给分析器。

PUT /my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "folding": {
          "tokenizer": "standard",
          "filter":  [ "lowercase", "asciifolding" ]
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "text": {
          "type": "string",
          "analyzer": "folding"
        }
      }
    }
  }
}

POST /my_index/test/1
{
  "text": "olá"
}

GET /my_index/test/_search
{
  "fielddata_fields": ["text"]
}

结果:

   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "my_indexxx",
            "_type": "test",
            "_id": "1",
            "_score": 1,
            "_source": {
               "text": "olá"
            },
            "fields": {
               "text": [
                  "ola"
               ]
            }
         }
      ]
   }

【讨论】:

  • 没错!是浏览器编码和感知接口的问题!
  • 它直接使用浏览器工作:localhost:9200/my_index/… 非常感谢! :)
【解决方案2】:

使用更多recent versions of elasticsearch,您可以像这样传递"asciifolding"令牌过滤器:

PUT index_name
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": { 
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "asciifolding"
          ]
        }
      }
    }
  }
}

示例查询:

POST index_name/_analyze
{
  "analyzer": "my_analyzer",
  "text": "olá"
}

输出:

{
  "tokens": [
    {
      "token": "ola",
      "start_offset": 0,
      "end_offset": 3,
      "type": "<ALPHANUM>",
      "position": 0
    }
  ]
}

【讨论】:

    【解决方案3】:

    上面的例子对我不起作用..经过一些调整,以下在 Elastic search 7.3.1 中起作用:

    删除索引(如果以前创建过):

    DELETE /my_index
    

    定义索引的映射:

    PUT /my_index
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "folding": {
              "tokenizer": "standard",
              "filter": [
                "lowercase",
                "asciifolding"
              ]
            }
          }
        }
      },
      "mappings": {
        "properties": {
          "text": {
            "type": "text",
            "analyzer": "folding",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
    }
    

    添加一些数据:

    POST my_index/_doc/1
    {"text":"olá"}
    

    执行搜索:

    GET /my_index/_search
    {
      "query": {
        "query_string": {
          "query": "ola"
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      • 2017-10-18
      • 2017-11-08
      • 2016-12-01
      • 2017-10-06
      • 2015-07-19
      • 1970-01-01
      相关资源
      最近更新 更多