Elasticsearch-php: Completion Suggest index create failed

Created on 22 Feb 2016  ·  4Comments  ·  Source: elastic/elasticsearch-php

Hi@all,

how i can create completion suggest index?

Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html#_why_another_suggester_why_not_prefix_queries

$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. :(

Most helpful comment

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

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings