Filtering queryStringQuery by exact match first (Nest)


(saadoune abderrahmane) #1

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()},
            },
        };

(Russ Cam) #2

@Abderrahmane_Saadoun, please can you format your code, using </> icon as explained in this guide. 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:

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


(saadoune abderrahmane) #3

Hello thanks for your reply

I have formated my text as asked.


(Russ Cam) #4

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?


(saadoune abderrahmane) #5

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.


(system) closed #6

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