# Elasticsearch missing results and incorrect sorting

**URL:** <https://discuss.elastic.co/t/elasticsearch-missing-results-and-incorrect-sorting/284930>\
**Category:** Elasticsearch\
**Created:** [September 22, 2021, 6:44pm UTC](https://discuss.elastic.co/t/elasticsearch-missing-results-and-incorrect-sorting/284930 "2021-09-22T18:44:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Miller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike_miller/32/94953_2.png) [@Mike\_Miller](https://discuss.elastic.co/u/Mike_Miller)\
**Post date:** [September 22, 2021, 6:44pm UTC](https://discuss.elastic.co/t/elasticsearch-missing-results-and-incorrect-sorting/284930/1 "2021-09-22T18:44:13Z")

</div>

I have Elasticsearch setup for searching book content. It works for the most part, however it frequently misses single search terms, especially in the 'entryTitle'. An example is in one book there is a Section title called "Parks and Recreation", however with the search term 'parks' it does not find it.

It also for my use case ideally should be prioritizing the results from the 'entryTitle' over the 'entryContent' results.

The current query is:

```auto
 $params = [
                'index' => 'toc_entries',
                'type' => '_doc',
                'body' => [
                    'min_score' => '0.1',
                    'sort' => [
                        '_score'
                    ],
                    '_source' => [
                        'entryTitle',
                        'entryId'
                    ],
                    'query' => [
                        'bool' => [
                            'filter' => [
                                'term' => [
                                    'bookSku.raw' => $sku
                                ]
                            ],
                            'should' => [
                                [
                                    'match' => [
                                        'entryTitle' => [
                                            'query' => $search_term,
                                            '_name' => 'title'
                                        ]
                                    ]
                                ],
                                [
                                    'match' => [
                                        'entryContent' => [
                                            'query' => $search_term,
                                            '_name' => 'body'
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ],
                    'highlight' => [
                        'pre_tags' => [''],
                        'post_tags' => [''],
                        'fields' => [
                            'entryContent' => new \stdClass(),
                            'entryTitle' => new \stdClass()
                        ]
                    ]
                ]
            ];

```

Can any Elasticsearch experts see where I have gone wrong here?

Thank you in advance

Edit:

Here is the structure of the setup:

```auto
{
   "analysis":{
      "analyzer":{
         "default":{
            "type":"english"
         }
      }
   },
   "settings":{
      "number_of_shards":1,
      "number_of_replicas":1
   },
   "mappings":{
      "_default_":{
         "dynamic":"strict"
      },
      "_doc":{
         "properties":{
            "bookSku":{
               "type":"text",
               "fields":{
                  "raw":{
                     "type":"keyword"
                  }
               }
            },
            "entryId":{
               "type":"text",
               "fields":{
                  "raw":{
                     "type":"keyword"
                  }
               }
            },
            "entryTitle":{
               "type":"text"
            },
            "entryContent":{
               "type":"text"
            }
         }
      }
   }
}

```

---

<div class="post-metadata">

**Author:** ![John\_Blazic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/john_blazic/32/77955_2.png) [@John\_Blazic](https://discuss.elastic.co/u/John_Blazic)\
**Post date:** [September 22, 2021, 6:57pm UTC](https://discuss.elastic.co/t/elasticsearch-missing-results-and-incorrect-sorting/284930/2 "2021-09-22T18:57:12Z")

</div>

For prioritizing one field over another, you'll want to use score boosting. You can't apply boosting to match queries directly according to the documentation, but you can apply them to booleans, so you could wrap your match queries for content and title in their own boolean queries with each in the must, giving the boolean wrapping the title a boost that is higher than the content. You'll need to experiment with the boost value to get it to function exactly how you would like though, as you can easily not boost it enough or too much.

Without seeing how you've indexed the title and content fields (i.e. what field types they are, which analyzers are applied at index time and query time), I don't think I can tell you much about why you're not getting an individual word back. If you can add that info, I might be able to parse it and help?

---

<div class="post-metadata">

**Author:** ![Mike\_Miller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike_miller/32/94953_2.png) [@Mike\_Miller](https://discuss.elastic.co/u/Mike_Miller)\
**Post date:** [September 22, 2021, 8:30pm UTC](https://discuss.elastic.co/t/elasticsearch-missing-results-and-incorrect-sorting/284930/3 "2021-09-22T20:30:12Z")

</div>

I have edited the original post with detail on the structure.

---

<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:** [October 20, 2021, 8:30pm UTC](https://discuss.elastic.co/t/elasticsearch-missing-results-and-incorrect-sorting/284930/4 "2021-10-20T20:30:14Z")

</div>

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