elasticsearch:忽略数字和特殊字符按字母顺序排序

wtlkbnrh  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(520)

如何按字母顺序排列文本字段,忽略特殊字符和数字?默认情况下,特殊字符排在数字和字母之后。
我需要的是字母表应该被排序并首先出现,然后是数字和特殊字符。这在es 6.3中可能吗?
我尝试使用自定义分析器替换所有非字母字符,但没有成功:

{
  "analysis": {
    "analyzer": {
      "alphabets_analyzer": {
        "tokenizer": "standard",
        "type": "keyword",
        "char_filter": [
          "alphabets_char_filter"
        ]
      }
    },
    "char_filter": {
      "alphabets_char_filter": {
        "type": "pattern_replace",
        "pattern": "[^a-zA-Z\\s\\.]",
        "replacement": ""
      }
    }
  }
}
5anewei6

5anewei61#

我可以通过以下索引级别的设置来解决此问题:

{
  "analysis": {
    "analyzer": {
      "alphabetsStringAnalyzer": {
        "tokenizer": "standard",
        "filter": "lowercase",
        "type": "custom",
        "char_filter": [
          "alphabets_char_filter"
        ]
      }
    },
    "char_filter": {
      "alphabets_char_filter": {
        "type": "pattern_replace",
        "pattern": "[^a-zA-Z]",
        "replacement": ""
      }
    }
  }
}

并在索引Map中设置此分析器,如下所示:

"fullName":{
            "type": "keyword",
            "fields": {
                 "raw": {
                     "type": "text",
                     "analyzer": "alphabetsStringAnalyzer",
                     "fielddata": true
                 }
             }
          }

相关问题