# Highlighting is not working in complex query

**URL:** <https://discuss.elastic.co/t/highlighting-is-not-working-in-complex-query/27591>\
**Category:** Elasticsearch\
**Created:** [August 18, 2015, 1:35pm UTC](https://discuss.elastic.co/t/highlighting-is-not-working-in-complex-query/27591 "2015-08-18T13:35:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![N\_M\_10](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@N\_M\_10](https://discuss.elastic.co/u/N_M_10)\
**Post date:** [August 18, 2015, 1:35pm UTC](https://discuss.elastic.co/t/highlighting-is-not-working-in-complex-query/27591/1 "2015-08-18T13:35:19Z")

</div>

Hi,  
I wanted to use highlight in my query,

My Query is

```
$query = [
    "filtered" => [
        "query" => [
            "bool" => [
                "should" => [
                    [
                        'query_string' => [
                            'fields' => [
                                'Title.title^4',
                                'Title.ngrams_front^2',
                                'Title.ngrams_back'
                            ],
                            'defaultOperator' => 'or',
                            'query' => $paramsObj->q
                        ]
                    ],
                    [
                        'query_string' => [
                            'auto_generate_phrase_queries' => 0,
                            'enable_position_increments' => false,
                            'fields' => [
                                'Title.title',
                                'Address',
                                'keys'
                            ],
                            'query' => $paramsObj->q,
                            'use_dis_max' => false,
                            'boost' => 2
                        ]
                    ],
                    [
                        'fuzzy' => [
                            'Title.title' => [
                                'value' => $paramsObj->q,
                                'boost' => 1,
                                'min_similarity' => 0.5,
                                'max_expansions' => 20,
                                'prefix_length' => 0
                            ]
                        ]
                    ]
                ]   
            ]
        ],

        "filter" => $filters
    ]	
];

```

I have tried nested query inside query because i knew highlight will come on same level as query, but still its not working,  
can anyone help me stating where the highlight part should go in my query?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [August 18, 2015, 3:07pm UTC](https://discuss.elastic.co/t/highlighting-is-not-working-in-complex-query/27591/2 "2015-08-18T15:07:00Z")

</div>

The highlighter goes as another "top level" parameter, next to `query`:

```php
$request = [
  'query' => [
    'filtered' => [
      ...
    ]
  ],
  'highlight' => [
      'fields' => [
        'my_higlighted_field' => (object) []
    ]
  ]
];

```

---

<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:** [July 5, 2017, 11:55pm UTC](https://discuss.elastic.co/t/highlighting-is-not-working-in-complex-query/27591/3 "2017-07-05T23:55:15Z")

</div>


