# Interval query hits wrongly

**URL:** <https://discuss.elastic.co/t/interval-query-hits-wrongly/231753>\
**Category:** Elasticsearch\
**Created:** [May 8, 2020, 2:57pm UTC](https://discuss.elastic.co/t/interval-query-hits-wrongly/231753 "2020-05-08T14:57:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shrestha](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@shrestha](https://discuss.elastic.co/u/shrestha)\
**Post date:** [May 8, 2020, 2:57pm UTC](https://discuss.elastic.co/t/interval-query-hits-wrongly/231753/1 "2020-05-08T14:57:25Z")

</div>

Here the query that I build:

```
> queryText = {"query":
> {
> "intervals": {
> searchFields: {
> "all_of": {
> "ordered": "true",
> "intervals": [
> {
> "match": {
> "query": queryTerm,
> "max_gaps": 2,
> "ordered": "true"
> 
> }
> }
> ]
> }
> }
> }
> },
> "highlight": {
> "pre_tags": ["<b>"],
> "post_tags": ["</b>"],
> "fields": {
> searchFields: {
> "number_of_fragments": 0,
> }
> },
> "order": "score"
> }
> }

```

Using the above query, if I search for "vitamin a" in a document, it returns a document containing vitamin a, but it also highlight all the occurreces of "a" or "vitamin" which are far from each other.  
I have also tested with two intervals for each word i.e. for "vitamin" and for "a" but that also does not work.

Any suggestion or help is appreciated.  
Thanks.

---

<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:** [June 5, 2020, 2:57pm UTC](https://discuss.elastic.co/t/interval-query-hits-wrongly/231753/2 "2020-06-05T14:57:25Z")

</div>

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