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

使用Python创建Elasticsearch索引时遇analyser参数错误求助

解决方案

你遇到的错误核心原因是拼写错误:Elasticsearch使用美式拼写analyzer,但你代码里全部写成了英式拼写analyser,这导致Elasticsearch无法识别该参数。

修正步骤:

  • 将settings中analysis下的analyser改为analyzer
  • 将每个text字段定义里的analyser改为analyzer
  • 显式指定es.indices.create的index参数,符合Python API 7.x的规范

修正后的完整代码:

def create_expert_index(index_name="expert_query"):
    es = connect()

    if es.indices.exists(index=index_name):
        es.indices.delete(index=index_name, ignore=[400, 404])

    mappings = {
        "settings": {
            "analysis": {
                "analyzer": {  # 修正拼写:analyser → analyzer
                    "standard_asciifolding": {
                        "type": "custom",
                        "tokenizer": "standard",
                        "filter": ["asciifolding", "lowercase"]
                    }
                }
            }
        },
        "mappings": {
            "properties":
                {
                    "first_name":
                        {
                            "type": "text",
                            "analyzer": "standard_asciifolding"  # 修正拼写
                        },
                    "last_name":
                        {
                            "type": "text",
                            "analyzer": "standard_asciifolding"  # 修正拼写
                        },
                    "email":
                        {
                            "type": "text",
                            "analyzer": "standard_asciifolding"  # 修正拼写
                        },
                    "specializations":
                        {
                            "type": "text",
                            "analyzer": "standard_asciifolding"  # 修正拼写
                        },
                    "institution":
                        {
                            "type": "text",
                            "analyzer": "standard_asciifolding"  # 修正拼写
                        }
                }

        }
    }
    es.indices.create(index=index_name, body=mappings)

运行修正后的代码即可成功创建索引。

内容的提问来源于stack exchange,提问作者Francois Gosselin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 22:50:27