# How to favor adjacent words match, but to allow partial match too

**URL:** <https://discuss.elastic.co/t/how-to-favor-adjacent-words-match-but-to-allow-partial-match-too/372246>\
**Category:** Elastic Search\
**Created:** [December 19, 2024, 9:48pm UTC](https://discuss.elastic.co/t/how-to-favor-adjacent-words-match-but-to-allow-partial-match-too/372246 "2024-12-19T21:48:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitry\_S](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@Dmitry\_S](https://discuss.elastic.co/u/Dmitry_S)\
**Post date:** [December 19, 2024, 9:48pm UTC](https://discuss.elastic.co/t/how-to-favor-adjacent-words-match-but-to-allow-partial-match-too/372246/1 "2024-12-19T21:48:48Z")

</div>

I'm writing the text search app for some internal tool, so looking for some simple solution which doesn't require index-time changes (so not looking at N-gram indexing yet).

Let's say we have two documents with titles of same length

- " **Good document** about everything around"
- "Not **Good** but bad **document**"

Search phrase is "very **good document**".

Goal is to return both documents (i.e. allow partial match, as they don't have "very"), but also to boost " **Good document** about everything around" higher because " **good document**" are adjacent there.

In order to support boost by adjacent words match, it is usually recommended to use match\_phrase with slop. But it doesn't work in my case, because it doesn't allow partial match (doesn't allow to omit "very").

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [December 19, 2024, 10:00pm UTC](https://discuss.elastic.co/t/how-to-favor-adjacent-words-match-but-to-allow-partial-match-too/372246/2 "2024-12-19T22:00:28Z")

</div>

Why don't you create a boolean query, with clauses for `match_phrase` with slop and another `match` clause that would hit on your partial matches? You can experiment with `minimum_should_match` and if scoring is an issue you can also wrap it in a `dis_max` query.

---

<div class="post-metadata">

**Author:** ![Dmitry\_S](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@Dmitry\_S](https://discuss.elastic.co/u/Dmitry_S)\
**Post date:** [December 19, 2024, 10:13pm UTC](https://discuss.elastic.co/t/how-to-favor-adjacent-words-match-but-to-allow-partial-match-too/372246/3 "2024-12-19T22:13:19Z")

</div>

Do you mean I need to have `should` with `match_phrase` for all possible sub-strings of my initial query?

When query is relatively short ( "very **good document**"), then there will be only 3 sub-strings:

- "very good"
- "good document"
- "very good document"

But as a query gets longer, the number of sub-strings will grow fast.  
If this is the only option, I will try.

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [January 2, 2025, 1:37pm UTC](https://discuss.elastic.co/t/how-to-favor-adjacent-words-match-but-to-allow-partial-match-too/372246/4 "2025-01-02T13:37:29Z")

</div>

You shouldn't have to create individual clauses for each sub string. The `match` clause should return the documents that don't match the phrase 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 30, 2025, 1:37pm UTC](https://discuss.elastic.co/t/how-to-favor-adjacent-words-match-but-to-allow-partial-match-too/372246/5 "2025-01-30T13:37:55Z")

</div>

Closed on January 30, 2025, 1:37pm UTC

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