Highlight only the query

Viewed 78

I'm working with elasticsearch in php and try to use the highlight my params looks like that :

$params = [
     'index' => 'idx',
        'type' => 'type',
        'body' => [
            'query' => [
                'bool' => [
                    'should' => [
                           ['wildcard' => [
                            "identifier.contact.firstName" => '*' . $search . '*'
                        ]]
                     ]
                ]
            ],
            'sort' => [
                "id" => ["order" => "desc"]

            ],
            'highlight' => [
                'fields' => [
                    "identifier.contact.firstName" => new \stdClass()
                ],
            ]
        ],

So it works great except in my highlight field I have

<em> Nicolas </em> 

and what I want is

<em>Nico</em>las

So I tried several things like

'highlight' => [
                'fragment_size' => 5,
                'number_of_fragments' => 5,
                'fragmenter' => "span",
                'fields' => [
                    "identifier.contact.firstName" => new \stdClass()
                ],
            ]
 ]

or

'highlight' => [
                'fields' => [
                    "identifier.contact.firstName" => [
                        "fragment_size" => 5,
                        "number_of_fragments" => 5,
                        "fragmenter" => "span"
                    ],
                ]
]

But nothing changed. I also tried several value for fragment_size and number_of_fragment. I managed to deal with the problem with an algorithm which change the highlight but I find that pretty dirty

my config :

 'body' => [
                'settings' => [
                    'number_of_shards' => 5,
                    'number_of_replicas' => 0,
                    'analysis' => [
                        'my_analyzer' => [
                            "tokenizer" => "my_tokenizer"
                        ],
                        "tokenizer" => [
                            "my_tokenizer" => [
                                "type"=> "ngram",
                                "min_gram" => 1,
                                "max_gram" => 10,
                                "token_char" => [
                                    "letter",
                                    "digit"
                                ]
                            ]
                        ]
                    ]
                ],
0 Answers
Related