# Need Suggestion on match\_phrase\_prefix and field priority result top to bottom order

**URL:** <https://discuss.elastic.co/t/need-suggestion-on-match-phrase-prefix-and-field-priority-result-top-to-bottom-order/275728>\
**Category:** Elasticsearch\
**Created:** [June 12, 2021, 9:47am UTC](https://discuss.elastic.co/t/need-suggestion-on-match-phrase-prefix-and-field-priority-result-top-to-bottom-order/275728 "2021-06-12T09:47:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bikashelastic](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@bikashelastic](https://discuss.elastic.co/u/bikashelastic)\
**Post date:** [June 12, 2021, 9:47am UTC](https://discuss.elastic.co/t/need-suggestion-on-match-phrase-prefix-and-field-priority-result-top-to-bottom-order/275728/1 "2021-06-12T09:47:48Z")

</div>

Hy Team, I have implemented the bool query "match\_phrase\_prefix" with "slop" in my search functionality and the query is giving me the result as expected. but the order of the result is not giving the field priority.

We have 3 fields below and the order of the result should show the following priority if the keyword phrase is matched.

Title : 1 Priority  
Tag : 2 Priority  
Description : 3d

Search Keyword like: "3rd generation intel Xeon"

if the title match with the phrase then the title should come up on top then tag then the description as per priority.

Order of phrase search first in the title and with updated date order by  
Title: "3rd generation intel Xeon" ------Matched June-01-2021  
Title: "3rd generation intel Xeon" ----another title--Matched May-01-2021  
tag: "3rd generation intel Xeon" ------Matched June -02-2021  
des: "3rd generation intel Xeon" ------Matched  
title: "3rd generation" ------Matched  
des: "3rd generation" ------Matched  
tag: "intel Xeon" ------Matched

Here is my elastic query which I am currently used.

```auto
> {
> "query": {
> "constant_score": {
> "filter": {
> "bool": {
> "must": [
> {
> "match": {
> "category": {
> "query": "books",
> "operator": "or",
> "boost": 2
> }
> }
> }
> ],
> "should": [
> {
> "match_phrase_prefix": {
> "title": {
> "query": "3rd generation intel Xeon",
> "slop": 10,
> "boost": 3
> }
> }
> },
> {
> "match_phrase_prefix": {
> "description": {
> "query": "3rd generation intel Xeon",
> "slop": 10,
> "boost": 0.5
> }
> }
> },
> {
> "match_phrase_prefix": {
> "tag": {
> "query": "3rd generation intel Xeon",
> "slop": 10,
> "boost": 2
> }
> }
> }
> ],
> "must_not": [
> {
> "term": {
> "ndacontent": "1"
> }
> }
> ],
> "filter": []
> }
> }
> }
> },
> "aggs": {
> "associated": {
> "nested": {
> "path": "associated"
> },"sort":[  
> {  
> "updatedDate":{  
> "order":"desc"
> }
> }
> ], "aggs": {
> "associated_name": {
> "terms": {
> "field": "associated.id.keyword",
> "size": 1000
> }
> }
> }
> }
> }
> }

```

Any help that could appreciate

---

<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 10, 2021, 9:48am UTC](https://discuss.elastic.co/t/need-suggestion-on-match-phrase-prefix-and-field-priority-result-top-to-bottom-order/275728/2 "2021-07-10T09:48:21Z")

</div>

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