仅突出显示查询

时间:2017-09-15 08:22:27

标签: php elasticsearch

我在php中使用elasticsearch并尝试使用突出显示我的params看起来像:

$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()
                ],
            ]
        ],

除非我的highlight字段

,否则效果很好
<em> Nicolas </em> 

我想要的是

<em>Nico</em>las

所以我尝试了几件事,比如

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

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

但没有改变。我还为fragment_size和number_of_fragment尝试了几个值。我设法用一个改变突出显示的算法处理问题,但我觉得很脏

我的配置:

 '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 个答案:

没有答案