how i can create completion suggest index?
$client = ClientBuilder::create()->build();
$params = [
'index' => 'my_index',
'body' => [
'settings' => [
'number_of_shards' => 3,
'number_of_replicas' => 2
],
'mappings' => [
'category' => [
'_source' => [
'enabled' => true
],
'properties' => [
'name' => [
'type' => 'string'
]
]
]
]
]
];
$response = $client->indices()->create($params);
I have everthing tried. But i can't resolv the problem. :(
Than i tried like this:
$params = [
'index' => 'industryarena',
'body' => [
'settings' => [
'number_of_shards' => 1,
'number_of_replicas' => 0
],
'mappings' => [
'category' => [
'properties' => [
'name' => [
'type' => 'string'
],
'name_suggest' => [
'type' => 'completion',
'index_analyzer' => 'simple',
'search_analyzer' => 'simple',
'payloads' => true
]
],
],
]
]
];
$response = $this->elasticsearch->indices()->create($params);
I become a error like this:
[Elasticsearch\Common\Exceptions\BadRequest400Exception]
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"analyzer on completion field [name_suggest] must be set when search_analyzer is set"}],"type":"mapper_parsing_exception","reason":"Failed to parse
mapping [category]: analyzer on completion field [name_suggest] must be set when search_analyzer is set","caused_by":{"type":"mapper_parsing_exception","reason":"analyzer on completion field [name_suggest] must be
set when search_analyzer is set"}},"status":400}
Try using analyzer instead of index_analyzer. That changed in 2.x iirc
$params = [
'index' => 'industryarena',
'body' => [
'settings' => [
'number_of_shards' => 1,
'number_of_replicas' => 0
],
'mappings' => [
'category' => [
'properties' => [
'name' => [
'type' => 'string'
],
'name_suggest' => [
'type' => 'completion',
'analyzer' => 'simple',
'search_analyzer' => 'simple',
'payloads' => true
]
],
],
]
]
];
$response = $this->elasticsearch->indices()->create($params);
I just copied the request from http://demo.searchkit.co/
That works very well. Thanks.
Thank you so much @polyfractal , that was really helpful. I spent much time to figure that out, since it was my mapping document has been working until I upgrade to 2.4 fom 1.7
Most helpful comment
Try using
analyzerinstead ofindex_analyzer. That changed in 2.x iirc