# Require Elasticsearch highlight words enclosed with Double Quotes (") instead of chopping them

**URL:** <https://discuss.elastic.co/t/require-elasticsearch-highlight-words-enclosed-with-double-quotes-instead-of-chopping-them/190478>\
**Category:** Elasticsearch\
**Created:** [July 15, 2019, 9:41am UTC](https://discuss.elastic.co/t/require-elasticsearch-highlight-words-enclosed-with-double-quotes-instead-of-chopping-them/190478 "2019-07-15T09:41:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noctis17](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/noctis17/32/41656_2.png) [@Noctis17](https://discuss.elastic.co/u/Noctis17)\
**Post date:** [July 15, 2019, 9:41am UTC](https://discuss.elastic.co/t/require-elasticsearch-highlight-words-enclosed-with-double-quotes-instead-of-chopping-them/190478/1 "2019-07-15T09:41:32Z")

</div>

Elasticsearch: v7.2  
Application: PHP - Laravel v5.7

Hello and good day!

I'm developing a web application that is similar to a search engine, whereas a user will enter words that will be designated to the variable `$keywords` . Then I have this query to search throughout my index:

```auto
$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'from' => 0,
    'size' => 10,
    'body' => [
        "query" => [
            'bool' => [
                'must' => [
                    [
                        "query_string" => [
                            "fields" => ['title','content'],
                            "query" => $keywords
                        ]
                    ]
                ]
            ]
        ]
    ]
];

$articles = $client->search($params);

```

Now, in line with my previous [post](https://stackoverflow.com/questions/56932330/elasticsearch-count-number-of-keyword-occurences-in-a-document), I was able to count the number of occurrences my `$keywords` occurred within the documents of my index.

Here's my `highlight` query that is attached to the `$params` above:

```auto
"highlight" => [
    "fields" => [
        "content" => ["number_of_fragments" => 0],
        "title" => ["number_of_fragments" => 0]
    ]
    'require_field_match' => true
]

```

Even though that the `$keywords` are enclosed with double quotation mark ("), the `highlighter` still chops/separates the `$keywords` and I already specified them with double quotation mark to strictly follow these `words` .

For example, my $keywords contains `"Ayala Alabang"` , but as I displayed the output, it goes like this

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/8/9826bfebc82a4ba3c612cfd6230a40307aff7e8c.png)

The `$keywords` were separated, but according to the output, they're just adjacent to each other.

Is there any other tweaks or revision to my query? I found some related posts or questions in some forums, their last reply was from March 2019 but still no answers, any advice would be an greatly appreciated and an excellent help for this dilemma

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 19, 2019, 12:23pm UTC](https://discuss.elastic.co/t/require-elasticsearch-highlight-words-enclosed-with-double-quotes-instead-of-chopping-them/190478/2 "2019-07-19T12:23:40Z")

</div>

We have a number of [different highlighters](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html#set-highlighter-type) available which is a reflection of how many different people have attempted to tackle this tricky problem over the years.  
Some highlighter implementations are faster, some are better at highlighting phrases (your problem) than others. It's worth experimenting to see which offers the best trade off.

---

<div class="post-metadata">

**Author:** ![Noctis17](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/noctis17/32/41656_2.png) [@Noctis17](https://discuss.elastic.co/u/Noctis17)\
**Post date:** [July 19, 2019, 1:06pm UTC](https://discuss.elastic.co/t/require-elasticsearch-highlight-words-enclosed-with-double-quotes-instead-of-chopping-them/190478/3 "2019-07-19T13:06:48Z")

</div>

Hello sir @Mark_Harwood, thank you very much for your insight, appreciate it!

As for my problem, after several days of experimenting, I found the Elasticsearch search feature called `explain`. So I utilized that feature and was able to come up a solution that no longer requires highlights (coz it really gave me a hard time solving it BIG TIME)

Here's my thorough answer:

> <https://stackoverflow.com/questions/57036361/require-elasticsearch-highlight-words-enclosed-with-double-quotes-instead-of>

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 16, 2019, 1:06pm UTC](https://discuss.elastic.co/t/require-elasticsearch-highlight-words-enclosed-with-double-quotes-instead-of-chopping-them/190478/4 "2019-08-16T13:06:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
