为什么我不能使用分析仪获得“无法找到分析结果”的答案?

时间:2019-12-23 09:46:48

标签: php elasticsearch

我像文档(there)中那样使用分析器进行索引。

这是我创建的索引:

for (let i = 0; i < files.length; i++) { 
    formdata.append(`images[${i}]`, {
                    uri: pathOfFile,
                    name: fileName.jpg,
                    type: mimeType(eg. "image/jpeg")
    });
}

然后我尝试使用分析仪:

$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);

但我收到此消息:

  

'{“错误”:{“ root_cause”:[{“ type”:“ remote_transport_exception”,“原因”:“ [PEREGOVOR2] [127.0.0.1:9300] [索引:admin / analyze [s]]” }],“类型”:“ illegal_argument_exception”,“原因”:“失败   找到分析器[my_search_analyzer]“},”状态“:400}'

那么...我在做什么错?为什么我不能使用分析仪获得“无法找到分析结果”的答案?

1 个答案:

答案 0 :(得分:0)

您没有正确构建分析仪。您的设置只需要一个analyzer部分:

    $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);