Querying multiple fields and giving a predetermined score to an eventual match


#1

Hello there,
I'm quite new to ElasticSeach and i have been experiencing some serious difficulties trying to implement it the past few days.
I'm using ElasticSearch in a form on a website.
ES version is 1.4
The form possess some fields such as name, first-name, place, date of beginning, date of end.
I have very specific demands and I haven't been able to answer to one of them.
When someone fills the field "name" and press "search" i have been asked to provide results for matching on the full family name, a part of the family name, the full birth-name and a part of the birth-name.
Since i have very specific sort requirements the scores of the match on the full family name and the full birth-name must be very high and the same.
I had no problem doing it for the family name only :

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "myname",
            "fields": [
              "defunt.nom^30",
              "defunt.nom.ngram"
            ],
            "operator": "and"
          }
        }
      ]
    }
  },
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    },
    {
      "avis.parutions.datePublication": {
        "order": "desc"
      }
    },
    {
      "defunt.nom": {
        "order": "asc"
      }
    },
    {
      "defunt.prenom": {
        "order": "asc"
      }
    },
    {
      "avis.lieuxConcernes.ville": {
        "order": "asc"
      }
    },
    {
      "avis.ceremonie.adresse.ville": {
        "order": "asc"
      }
    }
  ]
}

But i can't do it for the birthname...
Keep in mind i can't make a separate "must" clause because there is no "birthname" field in the form. there is a birthname in the ES index which i have to query when someone query the family name.
Some other must clauses can be added if the user fill more fields too.

What i would like to have is something which would return all the documents which match the full family-name with a score of let's say 30, all the documents which match the full birth-name with the same score of 30 and finally all the documents which match partial family and birth names.

Any help would be greatly appreciated, if you need more details let me know and please forgive my english as it's not my native language.


(David Pilato) #2

Bonjour Arnaud

Please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

First, it's super urgent that you upgrade to 2.4 or better to 5.4. 1.x series is EOL'ed.

IMO that's a "bad" design. I mean that when you search for someone on Google, you don't have a complicated form to search. Just a box.
I like the fact that the search engine is built to take care of relevancy and gives the best results first.

Anyway, I know it's sometime hard to get a consensus on that.

I gave a talk (en fran├žais) at Paris JUG a year ago IIRC and I ended up showing a demo. The script is here:

Video (in french) is here:

I hope this can help. Feel free also to join our #in-your-native-tongue:discussions-en-francais group if you prefer speaking french.

Best


#3

I couldn't answer earlier but i wanted thank you for your answer Dadoonnet.
I reformatted my post using </> icon.
I'm aware of the fact that the elasticsearch version i use is deprecated and I'm trying to convince the team to upgrade.
Concerning the complex form, it probably won't change. This is how the project ownership and the project management teams decided it had to be. And since i just joined the team i won't be able to make some changes for a while. The very specific sorting instructions make it even worse.
Anyway, thanks for your answer and for the resources you posted, I'll give it a careful look.


(system) closed #4

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