# Elasticsearch complete sentence highlighting in span query

**URL:** <https://discuss.elastic.co/t/elasticsearch-complete-sentence-highlighting-in-span-query/219904>\
**Category:** Elasticsearch\
**Created:** [February 19, 2020, 6:41am UTC](https://discuss.elastic.co/t/elasticsearch-complete-sentence-highlighting-in-span-query/219904 "2020-02-19T06:41:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kartik\_puri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kartik_puri/32/62910_2.png) [@kartik\_puri](https://discuss.elastic.co/u/kartik_puri)\
**Post date:** [February 19, 2020, 6:41am UTC](https://discuss.elastic.co/t/elasticsearch-complete-sentence-highlighting-in-span-query/219904/1 "2020-02-19T06:41:09Z")

</div>

We have a situation where we are building a proximity search using the span queries to get the search results. Since we are using the span query we would like to highlight the complete sentence rather than search keywords.  
let's say we have a document with "The quick brown fox jumps over the lazy dog"

For example, if we search "quick over" with slop distance of 3 my query return "The **quick** brown fox jumps **over** the lazy dog" but it only highlights the quick and over. What I really want to highlight is the complete matched sentence which is "The **quick brown fox jumps over** the lazy dog".

Any help would be much appreciated

Please refer the following query which we have written

```auto
"query": {
            "bool": {
                "must": [{
                    "span_near": {
                        "clauses": [
                            {"span_term": {"description": "quick"}},
                            {"span_term": {"description": "over"}}
                        ],
                        "slop": 3,
                        "in_order":false
                    }
                }]
            }
        },
        "highlight": {
            "fields": {
                "description": {
                    "pre_tags": ["<b class='highlight_color'>"],
                    "post_tags": ['</b>'],
                    "number_of_fragments": 15,
                    "boundary_scanner": "sentence",
                    "boundary_chars": '.!?\t\n',
                    "fragment_size": 0
                }
            }
        }

```

---

<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:** [March 18, 2020, 6:41am UTC](https://discuss.elastic.co/t/elasticsearch-complete-sentence-highlighting-in-span-query/219904/2 "2020-03-18T06:41:24Z")

</div>

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