larasearch icon indicating copy to clipboard operation
larasearch copied to clipboard

suggest is not working

Open fuess opened this issue 10 years ago • 0 comments

Hi! I have two Eloquent models Eventdate and Event:

class EventDate {

    use SearchableTrait;

    public static $__es_config = [
        'suggest'       => ['event.name', 'event.excerpt', 'event.description']
    ];


    public function event()
    {
        return $this->belongsTo(Event::class);
    }


class Event {
    use CallableTrait;

    public function dates()
    {
        return $this->hasMany(EventDate::class);
    }

I run the index process with: php artisan larasearch:paths --relations --write-config Namespace\EventDate php artisan larasearch:reindex --relations Namespace\EventDate

The index is created and I can succesfully do simple (exact match) searches. But I can't get suggestions to work, although I have them set up in the $__es_config property.

The response always gives me an empty options array:

{
    "_shards": {
        "total": 1,
        "successful": 1,
        "failed": 0
    },
    "my-suggestion": [{
        "text": "search_term_with_typo",
        "offset": 0,
        "length": 16,
        "options": []
    }]
}

I use the elasticsearch/elasticsearch package to query the index:

$getMappingParams['index'] = 'event_dates_20150804140349';
$client->indices()->getMapping($getMappingParams);

This gives me a huge array, but the (maybe) relevant parts looks like this:

[event_dates_20150804140349] => Array
    [mappings] => Array
        [_default_]  => Array

            ...dynamic templates...

            [properties] => Array
                (
                    [event] => Array
                        (
                            [properties] => Array
                                (
                                    [description] => Array
                                        (
                                            [type] => string
                                            [index] => not_analyzed
                                            [fields] => Array
                                                (
                                                    [analyzed] => Array
                                                        (
                                                            [type] => string
                                                        )

                                                    [suggest] => Array
                                                        (
                                                            [type] => string
                                                            [analyzer] => larasearch_suggest_index
                                                        )

                                                )

                                        )
                                )
                        )
                )


        [event_date] => Array
            (
                [properties] => Array
                    (
                        [event] => Array
                            (
                                [properties] => Array
                                    (
                                        [description] => Array
                                            (
                                                [type] => string
                                                [index] => not_analyzed
                                                [fields] => Array
                                                    (
                                                        [analyzed] => Array
                                                            (
                                                                [type] => string
                                                             )
                                                        [suggest] => Array
                                                        (
                                                            [type] => string
                                                            [analyzer] => larasearch_suggest_index
                                                         )
                                                    )
                                            )
                                    )
                            )
                    )
            )
    )
)

In the bottom part you can see that [index] is not_analyzed. Shouldn't that be analyzed? Although the [fields] do have an analyzed array and suggest array. Don't know if I'm searching in the right direction? Is the mapping incorrect?

Can someone help with this? Thanks!

fuess avatar Aug 05 '15 11:08 fuess