You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

含撇号的Mapping搜索分析器无法正常工作

Troubleshooting Your Non-Working Apostrophe Char Filter in Elasticsearch

Got it, let's walk through why your quote-converting char filter isn't kicking in—this is a common gotcha, so we'll cover the most likely fixes:

Defining the quotes char filter in your settings is only half the job. You need to wrap it into a custom analyzer and assign that analyzer to your text field(s). Without this, Elasticsearch ignores the char filter entirely.

Here's what a complete, working configuration looks like:

{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "analysis": {
      "char_filter": {
        "quotes": {
          "type": "mapping",
          "mappings": [
            "\\u0091=>\\u0027",
            "\\u0092=>\\u0027",
            "\\u2018=>\\u0027",
            "\\u2019=>\\u0027",
            "\\u201B=>\\u0027"
          ]
        }
      },
      "analyzer": {
        "quote_normalized_analyzer": {
          "char_filter": ["quotes"], // Attach your char filter here
          "tokenizer": "standard",
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "your_target_field": { // Replace with your actual field name
        "type": "text",
        "analyzer": "quote_normalized_analyzer" // Use the custom analyzer here
      }
    }
  }
}

2. Verify the analyzer is actually processing your text

Don't guess—test it directly with the _analyze API to confirm the char filter is working. Run this request against your index:

POST /your_index_name/_analyze
{
  "analyzer": "quote_normalized_analyzer",
  "text": "It’s a test with curly apostrophes: ‘hello’ and ’world’"
}

Look at the returned tokens—you should see it's instead of it’s, and 'hello' instead of ‘hello’. If you don't, double-check your char filter mappings and analyzer setup.

3. You can't modify existing fields' analyzers (rebuild if needed)

If you already created the index without linking the char filter to an analyzer, you can't retroactively change the field's analyzer. You'll need to:

  • Create a new index with the correct settings/mapping
  • Reindex your data from the old index to the new one

4. Double-check your Unicode escape sequences

Your mapping uses \\u0091 (escaped backslash) which is correct for JSON—since JSON requires backslashes to be escaped. If you accidentally used a single backslash (\u0091), the mapping will break silently, so confirm that part of your config is intact.

Give these steps a go, and if you're still stuck, share your full index settings and mapping so we can troubleshoot further!

内容的提问来源于stack exchange,提问作者Adam Benson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:23:43