1
votes

I made my index with analyzer like in documentation (there).

This is my index create:

$params = [
    'index' => 'mytestindex',
    'body' => [
        'settings' => [
            'analysis' => [
                'index_analyzer' => [
                    'my_index_analyzer' => [
                        'type' => 'custom',
                        'tokenizer' => 'standard',
                        'filter' => [
                            'lowercase',
                            'mynGram2'
                        ],
                    ],
                ],
                'search_analyzer' => [
                    'my_search_analyzer' => [
                        'type' => 'custom',
                        'tokenizer' => 'standard',
                        'filter' => [
                            'standard',
                            'lowercase',
                            'mynGram2'
                        ],
                    ],
                ],
                'filter' => [
                    'mynGram2' => [
                        'type' => 'nGram',
                        'min_gram' => 2,
                        'max_gram' => 20,
                    ],
                ],
            ],
            'max_ngram_diff' => 50,
        ],
    ],
];
$x = $this->obj->indices()->create($params);

Then i try use my analyzer:

$params = [
    'index' => 'mytestindex',
    'body' => [
        'analyzer' => 'my_search_analyzer',
        'text' => 'текст проверить чтобы'
    ],
];
$x = $this->obj->indices()->analyze($params);

But I get this message:

'{"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[PEREGOVOR2][127.0.0.1:9300][indices:admin/analyze[s]]"}],"type":"illegal_argument_exception","reason":"failed to find analyzer [my_search_analyzer]"},"status":400}'

So... what am I doing wrong? Why can't I use my analyzer and get answer 'failed to find analyze'?

1

1 Answers

0
votes

You're not building your analyzer correctly. You only need one analyzer section in your settings:

    $params = [
    'index' => 'mytestindex',
    'body' => [
        'settings' => [
            'analysis' => [
                'analyzer' => [                           <--- change this
                    'my_index_analyzer' => [
                        'type' => 'custom',
                        "tokenizer" => "standard",
                        'filter' => [
                            "lowercase",
                            "mynGram2"
                        ],
                    ],
                    'my_search_analyzer' => [
                        "type" => "custom",
                        "tokenizer" => "standard",
                        'filter' => [
                            "standard",
                            "lowercase",
                            "mynGram2"
                        ],
                    ],
                ],
                'filter' => [
                    'mynGram2' => [
                        "type" => "nGram",
                        "min_gram" => 2,
                        "max_gram" => 20,
                    ],
                ],
            ],
            "max_ngram_diff" => "50",
        ],
    ],
];
$x = $this->obj->indices()->create($params);