# May I search among some fields, but use another field's matching score for sorting?

**URL:** https://discuss.elastic.co/t/may-i-search-among-some-fields-but-use-another-fields-matching-score-for-sorting/1308
**Category:** Elasticsearch
**Created:** [May 26, 2015, 11:45am UTC](https://discuss.elastic.co/t/may-i-search-among-some-fields-but-use-another-fields-matching-score-for-sorting/1308 "2015-05-26T11:45:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jffifa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jffifa/32/44820_2.png) [@jffifa](https://discuss.elastic.co/u/jffifa)
#### Post date: [May 26, 2015, 11:45am UTC](https://discuss.elastic.co/t/may-i-search-among-some-fields-but-use-another-fields-matching-score-for-sorting/1308/1 "2015-05-26T11:45:09Z")

</div>

I have some documents like this

```
{"id":1,"city":"London","content":"soccer","continent":"Europe"},
{"id":2,"city":"New York","content":"basketball","continent":"North America"},
{"id":3,"city":"Tokyo","content":"baseball","continent":"Asia"},
...

```

I need to search keywords among some fields(excluding `city` field), e.g. a query like

```
{"query":{"bool":{
    "should":[ //SHOULD_CLAUSE
        "match":{"continent":"America"},
        "term":{"content":"soccer"}
    ]
}}}

```

To make the results more "personalized", I want to make matched documents whose `city` field is the same as the visiting user's `city` property.  
However, if I make `city` as a query field(something like `"match":{"city":"Tokyo"}`) in `should` boolean clause, it may return some documents that only match the `city` field, which mismatch the fields I need to search. When using `boost` to make `city` field more "important" for sorting things goes worse.  
How can I achieve my goal?

It seems that a possible way write the `SHOULD_CLAUSE` part twice and make one of it combined with `city` clause using `and`

```
{"query":{"bool":{
    "should":[
        {"bool":{"must":[
            {"bool":{SHOULD_CLAUSE}},
            {"match":{"city":{"query":"Tokyo","boost":4.0}}}
        ]}},
        {"bool":{SHOULD_CLAUSE}}
    ]
}}}

```

But under the real circumstance the `SHOULD_CLAUSE` part may be more complicated and the whole query seems too long to write. I wonder if there is a better way.

---

<div class="post-metadata">

### Author: ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)
#### Post date: [May 26, 2015, 12:55pm UTC](https://discuss.elastic.co/t/may-i-search-among-some-fields-but-use-another-fields-matching-score-for-sorting/1308/2 "2015-05-26T12:55:27Z")

</div>

are you already test to use [minimum-should-match](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html) ?  
you can show us your query and the mapping for your index ?

---

<div class="post-metadata">

### Author: ![jffifa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jffifa/32/44820_2.png) [@jffifa](https://discuss.elastic.co/u/jffifa)
#### Post date: [May 26, 2015, 4:51pm UTC](https://discuss.elastic.co/t/may-i-search-among-some-fields-but-use-another-fields-matching-score-for-sorting/1308/3 "2015-05-26T16:51:28Z")

</div>

Hi Sierra,

I've edited my question, adding some samples to make it more clear to unserstand.

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [May 26, 2015, 5:05pm UTC](https://discuss.elastic.co/t/may-i-search-among-some-fields-but-use-another-fields-matching-score-for-sorting/1308/4 "2015-05-26T17:05:08Z")

</div>

You can make a query's score not count by wrapping it in a constant score query or a filter like a query\_filter. Maybe you can just wrap the bits you don't want to score in one of those?

---

<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 6, 2017, 12:11am UTC](https://discuss.elastic.co/t/may-i-search-among-some-fields-but-use-another-fields-matching-score-for-sorting/1308/5 "2017-07-06T00:11:50Z")

</div>


