# Elasticsearch not returning expected results at end of query

**URL:** https://discuss.elastic.co/t/elasticsearch-not-returning-expected-results-at-end-of-query/45323
**Category:** Elasticsearch
**Created:** [March 24, 2016, 9:37am UTC](https://discuss.elastic.co/t/elasticsearch-not-returning-expected-results-at-end-of-query/45323 "2016-03-24T09:37:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Ben\_Squire](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ben_squire/32/8659_2.png) [@Ben\_Squire](https://discuss.elastic.co/u/Ben_Squire)
#### Post date: [March 24, 2016, 9:37am UTC](https://discuss.elastic.co/t/elasticsearch-not-returning-expected-results-at-end-of-query/45323/1 "2016-03-24T09:37:06Z")

</div>

Hi All,

A little help/understanding would be greatly appreciated 🙂

Here is my index:

```
    [
        'index' => 'proof',
        'body' => [
            'settings' => [
                'analysis' => [
                    'tokenizer' => [
                        'ngram_tokenizer' => [
                            'type' => 'nGram',
                            'min_gram' => 1,
                            'max_gram' => 20,
                            'token_chars' => ['letter', 'digit'],
                        ],
                    ],
                    'analyzer' => [
                        'ngram_tokenizer_analyzer' => [
                            'type' => 'custom',
                            'tokenizer' => 'ngram_tokenizer',
                            'filter' => ['lowercase'],
                        ]
                    ]
                ]
            ],
            'mappings' => [
                'proof_page' => [
                    'properties' => [
                        'content' => [
                            'type' => 'multi_field',
                            'path' => 'just_name',
                            'fields' => [
                                'content' => [
                                    'type' => 'string',
                                    'analyzer' => 'ngram_tokenizer_analyzer',
                                ],
                                'untouched' => [
                                    'type' => 'string'
                                ]
                            ]
                        ],
                        'page_number' => [
                            'type' => 'integer',
                            'index' => 'not_analyzed',
                        ],
                        'proof_id' => [
                            'type' => 'string',
                            'index' => 'not_analyzed',
                        ],
                    ]
                ]
            ]
        ]
    ]

```

and here is a sample query:

```
[
    'index' => 'proof',
    'type' => 'proof_page',
    'body' => [
        'query' => [
            'filtered' => [
                'query' => [
                    'match_phrase' => [
                        'content' => [
                            'query' => 'Lorem Ipsum is simply dum',
                            'slop' => 0,
                        ],
                    ],
                ],
                'filter' => [
                    'term' => [
                        'proof_id' => '56ebea535f5e8841038b4569',
                    ],
                ],
            ],
        ],
        '_source' => false,
        'fields' => [
            'proof_id',
            'proof_name',
            'project_id',
            'project_name',
            'page_number',
        ],
        'highlight' => [
            'fields' => [
                'content' => [
                    'type' => 'plain',
                    'fragment_size' => 100,
                    'number_of_fragments' => 100,
                    'fragmenter' => 'simple',
                ]
            ]
        ],
        'from' => 0,
        'size' => 10,
        'sort' => [
            'page_number' => [
                'order' => 'asc',
            ]
        ]
    ]
]

```

and lets assume that one of my documents that matches proof\_id: 56ebea535f5e8841038b4569 containes something like:

```
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.

```

What I'd expect to see is the result returning a snippet with the following highlighted:

```
Lorem Ipsum is simply dum

```

but it doesn't return any matches, the same is the case for:

```
Lorem Ipsum is simply du
Lorem Ipsum is simply dumm

```

However it does return matches for:

```
Lorem Ipsum is simply d
Lorem Ipsum is simply dummy

```

which makes no sense to me as I can see every variation of "dummy" as vector terms (the ngram is big enough to cover all variations).

Its worth pointing out that this only happens with terms at the end of the search string. So for example:

```
m Ipsum is simply d
em Ipsum is simply d
rem Ipsum is simply d
orem Ipsum is simply d
Lorem Ipsum is simply d

```

all highlight as expected.

Thanks all!

Ben

---

<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:05pm UTC](https://discuss.elastic.co/t/elasticsearch-not-returning-expected-results-at-end-of-query/45323/2 "2017-07-05T23:05:34Z")

</div>


