# Elasticsearch Highlighting is very slow

**URL:** <https://discuss.elastic.co/t/elasticsearch-highlighting-is-very-slow/160680>\
**Category:** Elasticsearch\
**Created:** [December 13, 2018, 7:26am UTC](https://discuss.elastic.co/t/elasticsearch-highlighting-is-very-slow/160680 "2018-12-13T07:26:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikesh/32/86579_2.png) [@Nikesh](https://discuss.elastic.co/u/Nikesh)\
**Post date:** [December 13, 2018, 7:26am UTC](https://discuss.elastic.co/t/elasticsearch-highlighting-is-very-slow/160680/1 "2018-12-13T07:26:09Z")

</div>

Hi,  
I find unified highlighting is taking a long time to fetch highlight results. I wish to know why there is huge difference when using highlighting  
I am using "term\_vector": "with\_positions\_offsets" on all the fields that has to be highlighted  
My query is as below without highlight :

```
{
  "from": 0,
  "size": 24,
  "query": {
    "bool": { "should": [
        { "bool": {
            "should": [
              { "query_string": {
                  "query": "\"tets\"",
                  "fields": [],
                  "boost": "50"
                } },
              {"multi_match": {
                  "query": "tets",
                  "type": "phrase",
                  "boost": "10",
                  "slop": "2",
                  "fields": [] } },
              { "multi_match": {
                  "query": "tets",
                  "fields": [] }},
              {"multi_match": {
                  "query": "tets",
                  "fuzziness": "AUTO",
                  "fields": [] } } ],
            "minimum_should_match": 1,
            "filter": [
              {
                "bool": {
                  "should": [
                    { "query_string": {
                        "query": "place:(California OR AndheriY OR Mumbai) AND SUB_TYPE_ID:(4028b204580517120158052c8b0b04dd OR 4028b204580517120158052c8b1804e0)"
                      } },
                    { "query_string": {
                        "query": "place:(California OR Germany OR Pune) AND SUB_TYPE_ID:(4028b204580517120158052c8b0b04dd OR 4028b204580517120158052c8b0f04de OR 4028b204580517120158052c8b1404df)" } },
                    {"query_string": {
                        "query": " !_exists_:plcae AND SUB_TYPE_ID:(4028b204580517120158052c8b0b04dd OR 4028b204580517120158052c8b1804e0 OR 4028b204580517120158052c8b0f04de OR 4028b204580517120158052c8b1404df)" } } ],
                  "minimum_should_match": 1
                } },
               {
                "bool": {
                  "should": [
                    {
                      "query_string": {
                        "query": "status:(Yes ) "
                      }
                    },
                    {
                      "query_string": {
                        "query": "status:(No) AND user:(6901)"
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              }
            ]
          }
        }
      ],
      "minimum_should_match": 1,
      "filter": [
        {
          "terms": {
            "ACTIVE.keyword": [
              "1"
            ]
          }
        },
        {
          "terms": {
            "FOLDER_ID.keyword": [
              2,
              8,
              9,
              12,
              14,
              -1
            ]
          }
        }
      ]
    }
  }
}

```

It takes around 42ms.

My query with highlight is :

```
{
  "from": 0,
  "size": 24,
  "query": {
    "bool": {
      "should": [
        {"bool": {
            "should": [
              {
                "query_string": {
                  "query": "\"tets\"",
                  "fields": [],
                  "boost": "50"
                }
              },
              {
                "multi_match": {
                  "query": "tets",
                  "type": "phrase",
                  "boost": "10",
                  "slop": "2",
                  "fields": []
                }
              },
              { "multi_match": {
                  "query": "tets",
                  "fields": [] } },
              {"multi_match": {
                  "query": "tets",
                  "fuzziness": "AUTO",
                  "fields": [] } } ],
            "minimum_should_match": 1,
            "filter": [
              {
                "bool": {
                  "should": [
                    {
                      "query_string": {
                        "query": "place:(California OR AndheriY OR Mumbai) AND SUB_TYPE_ID:(4028b204580517120158052c8b0b04dd OR 4028b204580517120158052c8b1804e0)"
                      }
                    },
                    {
                      "query_string": {
                        "query": "place:(California OR Germany OR Pune) AND SUB_TYPE_ID:(4028b204580517120158052c8b0b04dd OR 4028b204580517120158052c8b0f04de OR 4028b204580517120158052c8b1404df)"
                      }
                    },
                    {
                      "query_string": {
                        "query": " !_exists_:place AND SUB_TYPE_ID:(4028b204580517120158052c8b0b04dd OR 4028b204580517120158052c8b1804e0 OR 4028b204580517120158052c8b0f04de OR 4028b204580517120158052c8b1404df)"
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              },
               {
                "bool": {
                  "should": [
                    {
                      "query_string": {
                        "query": "status:(Yes ) "
                      }
                    },
                    {
                      "query_string": {
                        "query": "status:(No) AND user:(6901)"
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              }
            ]
          }
        }
      ],
      "minimum_should_match": 1,
      "filter": [
        {
          "terms": {
            "ACTIVE.keyword": [
              "1"
            ]
          }
        },
        {
          "terms": {
            "FOLDER_ID.keyword": [
              2,
              8,
              9,
              12,
              14,
              -1
            ]
          }
        }
      ]
    }
  },
"highlight": {
        "type" : "unified",
        "fields": {
            "*": {
            }           	 
        }
    }
}

```

The same query with highlight is taking around 1951ms. This is about more than 45 times than without highlight query.  
I want to know the reason behind this delay and Is there a method to optimise the query ?

---

<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:** [January 10, 2019, 7:26am UTC](https://discuss.elastic.co/t/elasticsearch-highlighting-is-very-slow/160680/2 "2019-01-10T07:26:14Z")

</div>

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