Problems highlighting with bool + filter query and PHP API


(Joe) #1

Hi everyone,

I am having problems with highlighting in the PHP API. We are running on ES 1.7.
If a use a bool query for the search it does not return any highlighted results. The search itself works fine. However if a use a simple match_phrase query the highlighting works.
Here is a sample code of the search body:

$params = [
    'index' => $index,
    'type'  => $type,
    'body'  => [
        'from'			=> ( (int)$offset * $this->getSearchResultSize() ),
        'size'			=> $this->getSearchResultSize(),
        'indices_boost'	=> $this->getIndicesBoosts(),
        'sort'			=> $this->getSorting(),
        'query'			=> [
            'bool'      => [
                 'must'  => [
                     'term'      => [ '_all' => $query ],
                     'filter'	=> $this->getFilterConditions( $acl, $product, $spaceId )
                 ]
             ]
        ],
        'highlight'     => [
            'pre_tags'      => ['<span class="search-highlight">'],
            'post_tags'     => ['</span>'],
            'fields'        => [
                'content'       => [
                    'force_source'          => true,
                    'fragment_size'         => 100,
                    'number_of_fragments'   => 3
                ]
            ],
        ]
    ]
];

If i replace the bool query with

'match_phrase'	=> [
    'content' => $query
 ]

it works.

I already tried using the same query as in the search as highlight_query but that did not help either. Casting the fields array to an object also did not help.

Is there any way I can get the highlighting work with the bool query?

EDIT: The same applies for aggregations.

Thanks for your help!

Joe


(system) #2