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

Python创建Elasticsearch索引时使用指定映射报错求助

Python创建Elasticsearch索引时使用指定映射报错求助

各位好,我正在用Python的Elasticsearch客户端创建带自定义映射的索引,结果运行代码时遇到了报错,试了好几种调整都没解决,想请大伙帮忙看看问题出在哪。

下面是我的代码:

from elasticsearch import Elasticsearch

client = Elasticsearch(
    "https://myhost",
    api_key="mykey",
    request_timeout=30,  # Increase timeout duration
    max_retries=10,
    retry_on_timeout=True
)

dest_index = "course_info_eng_v3d6_destination"

client.indices.create(
    index=dest_index,
    mappings={
        "dynamic": "true",
        "dynamic_templates": [
            {
                "all_text_fields": {
                    "match_mapping_type": "string",
                    "mapping": {
                        "analyzer": "iq_text_base",
                        "fields": {
                            "delimiter": {
                                "analyzer": "iq_text_delimiter",
                                "type": "text",
                                "index_options": "freqs"
                            },
                            "joined": {
                                "search_analyzer": "q_text_bigram",
                                "analyzer": "i_text_bigram",
                                "type": "text",
                                "index_options": "freqs"
                            },
                            "prefix": {
                                "search_analyzer": "q_prefix",
                                "analyzer": "i_prefix",
                                "type": "text",
                                "index_options": "docs"
                            },
                            "enum": {
                                "ignore_above": 2048,
                                "type": "keyword"
                            },
                            "stem": {
                                "analyzer": "iq_text_stem",
                                "type": "text"
                            }
                        }
                    }
                }
            }
        ],
        "properties": {
            "course_id": {
                "type": "text",
                "fields": {
                    "delimiter": {
                        "type": "text",
                        "index_options": "freqs",
                        "analyzer": "iq_text_delimiter"
                    },
                    "enum": {
                        "type": "keyword",
                        "ignore_above": 2048
                    },
                    "joined": {
                        "type": "text",
                        "index_options": "freqs",
                        "analyzer": "i_text_bigram",
                        "search_analyzer": "q_text_bigram"
                    },
                    "prefix": {
                        "type": "text",
                        "index_options": "docs",
                        "analyzer": "i_prefix",
                        "search_analyzer": "q_prefix"
                    },
                    "stem": {
                        "type": "text",
                        "analyzer": "iq_text_stem"
                    }
                },
                "analyzer": "iq_text_base"
            },
            "course_name_backup": {
                "type": "text",
                "fields": {
                    "delimiter": {
                        "type": "text",
                        "index_options": "freqs",
                        "analyzer": "iq_text_delimiter"
                    },
                    "enum": {
                        "type": "keyword",
                        "ignore_above": 2048
                    },
                    "joined": {
                        "type": "text",
                        "index_options": "freqs",
                        "analyzer": "i_text_bigram",
                        "search_analyzer": "q_text_bigram"
                    },
                    "prefix": {
                        "type": "text",
                        "index_options": "docs",
                        "analyzer": "i_prefix",
                        "search_analyzer": "q_prefix"
                    },
                    "stem": {
                        "type": "text",
                        "analyzer": "iq_text_stem"
                    }
                },
                "analyzer": "iq_text_base"
            },
            "embedding": {
                "type": "dense_vector",
                "dims": 768,
                "index": "true",
                "similarity": "cosine",
                "index_options": {
                    "type": "int8_hnsw",
                    "m": 16,
                    "ef_construction": 100
                }
            },
            "language": {
                "type": "text",
                "fields": {
                    "delimiter": {
                        "type": "text",
                        "index_options": "freqs",
                        "analyzer": "iq_text_delimiter"
                    },
                    "enum": {
                        "type": "keyword",
                        "ignore_above": 2048
                    },
                    "joined": {
                        "type": "text",
                        "index_options": "freqs",
                        "analyzer": "i_text_bigram",
                        "search_analyzer": "q_text_bigram"
                    },
                    "prefix": {
                        "type": "text",
                        "index_options": "docs",
                        "analyzer": "i_prefix",
                        "search_analyzer": "q_prefix"
                    },
                    "stem": {
                        "type": "text",
                        "analyzer": "iq_text_stem"
                    }
                },
                "analyzer": "iq_text_base"
            },
            "provider": {
                "type": "text",
                "fields": {
                    "delimiter": {
                        "type": "text",
                        "index_options": "freqs",
                        "analyzer": "iq_text_delimiter"
                    },
                    "enum": {
                        "type": "keyword",
                        "ignore_above": 2048
                    },
                    "joined": {
                        "type": "text",
                        "index_options": "freqs",
                        "analyzer": "i_text_bigram",
                        "search_analyzer": "q_text_bigram"
                    },
                    "prefix": {

注:代码最后部分复制的时候截断了,但目前的配置里我主要是想给文本字段设置多字段的不同分析器,同时添加embedding的向量字段。执行创建索引的代码时直接报错了,有没有大佬能帮忙看看映射配置里的语法或者逻辑问题?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.07 09:38:07