# How to script a multi-match

**URL:** <https://discuss.elastic.co/t/how-to-script-a-multi-match/242589>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 25, 2020, 5:18am UTC](https://discuss.elastic.co/t/how-to-script-a-multi-match/242589 "2020-07-25T05:18:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wurzelsepp](https://avatars.discourse-cdn.com/v4/letter/w/f0a364/32.png) [@Wurzelsepp](https://discuss.elastic.co/u/Wurzelsepp)\
**Post date:** [July 25, 2020, 5:18am UTC](https://discuss.elastic.co/t/how-to-script-a-multi-match/242589/1 "2020-07-25T05:18:29Z")

</div>

Hi, I am trying to understand how a multi-match score could be scripted.  
Consider a list of publications, with sample data items like

```auto
{ "title": "Sounds of Silence", "author": [{ "first": "Paul", "last"_ "Simon" }, { "first": "Art", "last": "Garfunkel" }] }

```

Now I would like to start with matching just authors, so I need a multi-match on "first" and "last" fields. For the lastname, I want to use a similarity function like daitch\_mokotoff phonetic, for the first name I would like to add synonyms (e.g. Bob/Robert, Dick/Richard, Tim/Timothy)  
For the scoring I envision something like  
last name match: 1 point adjusted by spelling distance for 1 match, 1.5 points for a double match  
first name match: minimal contribution for first name only, value from last name multiplied by 1,3 for single or 1.6 for double first name match.  
I definitely do not want tf/idf for the names but would rather increase ranks for authors with many publications.

It would be great to allow searches like "T. Leary" with the abbreviation only for first name. It is no problem to replace "." in user input by \*, but I would probably need to verify that the T. matches on a first name rather than a last name

---

<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:** [August 22, 2020, 5:18am UTC](https://discuss.elastic.co/t/how-to-script-a-multi-match/242589/2 "2020-08-22T05:18:34Z")

</div>

Closed on August 22, 2020, 5:18am UTC

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