yiisoft / yii2-elasticsearch

Yii 2 Elasticsearch extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
427 stars 253 forks source link

Problem in creating index even I have one mapping array #294

Closed SobhieSad closed 3 years ago

SobhieSad commented 4 years ago

Hi, @samdark I have the following code for creating the index:

$command->createIndex(self::index(), [
               'settings' => [
                    "number_of_shards" => 2,
                    "index" => [
                        'refresh_interval' => '1s',],
                    "analysis" => [
                        "analyzer" => [
                            "synonym_analyzer" => [
                                "type" => "custom",
                                "tokenizer" => "standard",
                                "filter" => ["synonym_filter"]
                            ],
                            "lowercase_keyword_analyzer" => [
                                "tokenizer" => "keyword",
                                "filter" => [
                                    "lowercase"
                                ],
                            ]
                        ],
                        "filter" => [
                            "synonym_filter" => [
                                "type" => "synonym",
                                "synonyms_path" => "analysis/synonyms_list.txt"
                            ]
                        ]
                    ]
                ],
                "mappings" => static::mapping()
            ]);

where the mapping code is this:

 public static function mapping()
    {
        return [
                "properties" => [
                    'id' => ['type' => 'long'],
                    'title' => ['type' => 'text', "analyzer" => "lowercase_keyword_analyzer", "search_analyzer" => "synonym_analyzer"],
                    'is_helpful' => ['type' => 'integer'],
                    'is_not_helpful' => ['type' => 'integer'],
                    'description' => ['type' => 'text', 'index' => true],
                    'answer' => ['type' => 'text', 'index' => true],
                    'medical_reviewer' => ['type' => 'text', 'index' => true],
                    'include_tags' => ['type' => 'text'],
                    'exclude_tags' => ['type' => 'text', 'index' => true],
                    'topics' => ['type' => 'text'],
                    'related_questions' => ['type' => 'text'],
                    'language' => ['type' => 'text', 'index' => true],
                    'exclude_from' => ['type' => 'text', 'index' => true],
                    'synonyms_list' => ['type' => 'text', 'index' => true]
                ]
        ];
    }

but I got this error :

Elasticsearch request failed with code 400. Response body: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [question_index] as the final mapping would have more than 1 type: [_doc, questionTypeFinal]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [question_index] as the final mapping would have more than 1 type: [_doc, questionTypeFinal]"},"status":400}

I don't understand how it sees 2 types even I pass one only

beowulfenator commented 4 years ago

Are you sure the index does not exist already? Because it looks like you are updating an existing index that already has a mapping (questionTypeFinal). If the extension is properly configured for ES6+ it will attempt to create the default mapping (_doc).

Can you make sure that the index does not already exist? Try $command->deleteIndex(self::index()) before you run createIndex().

beowulfenator commented 4 years ago

Also, is it possible that your model has a type() method that returns questionTypeFinal?

beowulfenator commented 3 years ago

Closing due to inactivity.