A
A
Apostol632019-12-18 14:25:18
PHP
Apostol63, 2019-12-18 14:25:18

How to test analyzer in elasticsearch?

Good day to all!
Can you please tell me how to check the analyzer?
Here is the index code:

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

Here is the code to try to check:
$params = [
      'index' => 'mytestindex',
      'body' => [
        'analyzer' => 'my_search_analyzer',
        'text' => 'текст проверить чтобы'
      ],
    ];

    $x = $this->obj->indices()->analyze($params);

I use Elasticsearch\Client
So. Using the code above, I get the error failed to find analyzer.
I read on Google that this happens if index is not set directly, but simply something like:
$params = [
    'analyzer' => 'my_search_analyzer',
    'text' => 'текст проверить чтобы'
];
$x = $this->obj->indices()->analyze($params)

But I then set the index

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question