簡體   English   中英

帶有預定義映射的 Elasticsearch 問題,然后索引文檔

[英]Elasticsearch problem with pre-defined mapping and then index docs

我正在嘗試索引 stackoverflow 數據。 首先,我創建一個具有指定映射和設置的索引。

    @classmethod
    def create_index_with_set_map(cls, name, elasticsearch):
        """
        create index with default mappings and settings(and analyzer).

    Argument:
    name -- The name of the index.
    elasticsearch -- Elasticsearch instance for connection.
        """
     
        mappings = "mappings": {
            "properties": {
                "Body": {
                    "type": "text",
                    "analyzer": "whitespace",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }}}
       
        settings = {
            "analysis": {
                "analyzer": {
                    "default": {
                        "type": "whitespace"
                    }
                }
            }
        }

        body = {
            "settings": settings,
            "mappings": mappings

        }
        res = elasticsearch.indices.create(index=name, body=body)
        print(res)

然后我嘗試批量索引我的文檔:

@classmethod
    def start_index(cls, index_name, index_path, elasticsearch, doc_type):
        """
    This function is using bulk index.

    Argument:
    index_name -- the name of index
    index_path -- the path of xml file to index
    elasticsearch -- Elasticsearch instance for connection
    doc_type -- doc type 

    Returns:
    """

        for lines in Parser.xml_reader(index_path):
            actions = [
                {
                    "_index": index_name,
                    "_type": doc_type,
                    "_id": Parser.post_parser(line)['Id'],
                    "_source":  Parser.post_parser(line)


                }
                for line in lines if Parser.post_parser(line) is not None
            ]

            helpers.bulk(elasticsearch, actions)

鑒於錯誤:('500 個文檔未能建立索引。', [{'index': {'_index': 'sof-question-answer2', '_type': 'Stackoverflow', '_id': 1', 'status': 400, 'error': {'type': 'illegal_argument_exception', 'reason': 'Mapper for [Body] 與現有映射沖突:\\n[mapper [Body] 有不同的 [analyzer]]'}, '數據': ...}

看起來已經使用不同的分析器創建了sof-question-answer2索引,可能使用默認的standard analyzer

如果您通過 kibana 運行命令GET sof-question-answer2/_mapping ,您將看到Body字段沒有whitespace分析器。

為了解決這個問題,您必須刪除索引、更新映射並重新索引數據(如果有的話)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM