# Filtering queryStringQuery by exact match first (Nest)

**URL:** <https://discuss.elastic.co/t/filtering-querystringquery-by-exact-match-first-nest/169267>\
**Category:** Elasticsearch\
**Created:** [February 20, 2019, 5:14pm UTC](https://discuss.elastic.co/t/filtering-querystringquery-by-exact-match-first-nest/169267 "2019-02-20T17:14:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abderrahmane\_Saadoun](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Abderrahmane\_Saadoun](https://discuss.elastic.co/u/Abderrahmane_Saadoun)\
**Post date:** [February 20, 2019, 5:14pm UTC](https://discuss.elastic.co/t/filtering-querystringquery-by-exact-match-first-nest/169267/1 "2019-02-20T17:14:58Z")

</div>

Hello im new to elasticsearch and .net.

im trying to filter my results and show exact match first.

> Here is my mapping

```
  "formationContinues": {
       "properties": {
                        "dateObtention": {
                            "type": "integer"
                        },
                        "id": {
                            "type": "integer"
                        },
                        "organisme": {
                            "type": "text",
                            "boost": 1.5,
                            "analyzer": "english"
                        },
                        "pays": {
                            "properties": {
                                "code": {
                                    "type": "text",
                                    "fields": {
                                        "keyword": {
                                            "type": "keyword",
                                            "ignore_above": 256
                                        }
                                    }
                                },
                                "id": {
                                    "type": "integer"
                                },
                                "langue": {
                                    "type": "text",
                                    "fields": {
                                        "keyword": {
                                            "type": "keyword",
                                            "ignore_above": 256
                                        }
                                    }
                                },
                                "nom": {
                                    "type": "text",
                                    "boost": 2,
                                    "analyzer": "english"
                                }
                            }
                        },
                        "titre": {
                            "type": "text",
                            "boost": 1.5,
                            "analyzer": "english"
                        }
                    }
                }

```

> here is the settings

```
{"cv_search_dev_en": {
    "settings": {
        "index": {
            "number_of_shards": "5",
            "provided_name": "cv_search_dev_en",
            "creation_date": "1550583725461",
            "analysis": {
                "filter": {
                    "english_keywords": {
                        "keywords": [
                            "example"
                        ],
                        "type": "keyword_marker"
                    },
                    "english_stemmer": {
                        "type": "stemmer",
                        "language": "english"
                    },
                    "english_possessive_stemmer": {
                        "type": "stemmer",
                        "language": "possessive_english"
                    },
                    "english_stop": {
                        "type": "stop",
                        "stopwords": "_english_"
                    }
                },
                "analyzer": {
                    "english": {
                        "filter": [
                            "english_possessive_stemmer",
                            "lowercase",
                            "english_stop",
                            "english_keywords",
                            "english_stemmer",
                            "asciifolding",
                            "lowercase"
                        ],
                        "tokenizer": "standard"
                    },
                    "neutral_analyzer": {
                        "filter": [
                            "lowercase",
                            "english_stop",
                            "asciifolding"
                        ],
                        "tokenizer": "standard"
                    }
                }
            },
            "number_of_replicas": "1",
            "uuid": "n71tIFNEQoypjv5rzFhkEA",
            "version": {
                "created": "6030099"
            }
        }
    }
}

```

}

> here is the nest query:

```
QueryContainer queryContainer = new BoolQuery
        {
            Should = new QueryContainer[] {
                new QueryStringQuery { Query = query,DefaultOperator=Operator.Or, Fields = SearchFields.fields.ToArray()},
            },
        };

```

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 21, 2019, 2:12am UTC](https://discuss.elastic.co/t/filtering-querystringquery-by-exact-match-first-nest/169267/2 "2019-02-21T02:12:06Z")

</div>

@Abderrahmane_Saadoun, please can you format your code, using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for you to see how the formatting looks before posting.

---

<div class="post-metadata">

**Author:** ![Abderrahmane\_Saadoun](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Abderrahmane\_Saadoun](https://discuss.elastic.co/u/Abderrahmane_Saadoun)\
**Post date:** [February 21, 2019, 9:17am UTC](https://discuss.elastic.co/t/filtering-querystringquery-by-exact-match-first-nest/169267/3 "2019-02-21T09:17:44Z")

</div>

Hello thanks for your reply

I have formated my text as asked.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 21, 2019, 12:01pm UTC](https://discuss.elastic.co/t/filtering-querystringquery-by-exact-match-first-nest/169267/4 "2019-02-21T12:01:44Z")

</div>

Your question does not seem to include all the details to be able to answer it. For example,

- What is `SearchFields`?
- Which field(s) are you trying to target for an exact match?

Would you be able to provide a full, minimal, reproducible example that demonstrates the problem?

---

<div class="post-metadata">

**Author:** ![Abderrahmane\_Saadoun](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Abderrahmane\_Saadoun](https://discuss.elastic.co/u/Abderrahmane_Saadoun)\
**Post date:** [February 21, 2019, 1:42pm UTC](https://discuss.elastic.co/t/filtering-querystringquery-by-exact-match-first-nest/169267/5 "2019-02-21T13:42:58Z")

</div>

hello thanks again.

> Here is the searchFields :

```
{
 "formationContinues.titre^17",
 "formationContinues.organisme^16",
 "formationContinues.pays.nom^23",
}

```

> And i want to target all of the searchFields to show exact value first

> For example if i search for Salas, i get Sales,salé......... before the name Salas because the boost value is bigger than the others.

---

<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:** [March 21, 2019, 1:42pm UTC](https://discuss.elastic.co/t/filtering-querystringquery-by-exact-match-first-nest/169267/6 "2019-03-21T13:42:59Z")

</div>

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