# Python client multisearch with different fields weights

**URL:** <https://discuss.elastic.co/t/python-client-multisearch-with-different-fields-weights/354064>\
**Category:** Elasticsearch\
**Created:** [February 25, 2024, 6:39pm UTC](https://discuss.elastic.co/t/python-client-multisearch-with-different-fields-weights/354064 "2024-02-25T18:39:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Solari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_solari/32/131794_2.png) [@Marco\_Solari](https://discuss.elastic.co/u/Marco_Solari)\
**Post date:** [February 25, 2024, 6:39pm UTC](https://discuss.elastic.co/t/python-client-multisearch-with-different-fields-weights/354064/1 "2024-02-25T18:39:35Z")

</div>

I'm quite new to elasticsearch...  
I created my first index (to be used for italian language), and basic search functionality, for my cooking recipes database.

I now am trying to implement some more advanced search features, with multi-field search, giving different weights to different fields.

I use the Python ES client [[elasticsearch-py.readthedocs.io](http://elasticsearch-py.readthedocs.io), v8.12.1].

This is what I tried, without good results (titles seem to count, other fields do not...):

```auto
     query = {
        "multi_match": {
          "query": myQueryTerms,
          "fields": [
            "title^3", "ingredients^2", "descriptionSections", "category",
          ]
        }
      }

```

Can anybody help?

Unfortunately I find Python client for Elasticsearch API docs quite confusing, and difficult to browse...

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 25, 2024, 7:28pm UTC](https://discuss.elastic.co/t/python-client-multisearch-with-different-fields-weights/354064/2 "2024-02-25T19:28:23Z")

</div>

What is the mapping of the different fields you are searching? What does a sample query look like? How many matches are returned for this query? The default size is 10, so if you are getting 10 results returned it is possible there are other matches in addition to that.

If the result size is not an issue, can you show a document you would expect to match that does not?

---

<div class="post-metadata">

**Author:** ![Marco\_Solari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_solari/32/131794_2.png) [@Marco\_Solari](https://discuss.elastic.co/u/Marco_Solari)\
**Post date:** [February 26, 2024, 9:49am UTC](https://discuss.elastic.co/t/python-client-multisearch-with-different-fields-weights/354064/3 "2024-02-26T09:49:26Z")

</div>

Sorry for being short on details...

Mappings are:

```auto
{
  "properties": {
    "title": {
      "type": "text",
      "analyzer": "italian_full",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "language": {
      "type": "keyword"
    },
    "provider": {
      "type": "keyword"
    },
    "descriptionSections": {
      "properties": {
        "contents": {
          "type": "text",
          "analyzer": "italian_full"
        },
        "imageName": {
          "enabled": False
        },
        "imageUrl": {
          "enabled": False
        },
        "section": {
          "enabled": False
        }
      }
    },
    "category": {
      "type": "text",
      "analyzer": "italian_full",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 32
        }
      }
    },
    "ingredients": {
      "properties": {
        "title": {
          "enabled": False
        },
        "name": {
          "type": "text",
          "analyzer": "italian_full",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "unit": {
          "enabled": False
        }
      }
    },
    "imageUrl": {
      "enabled": False
    },
    "presentation": {
      "type": "text",
      "analyzer": "italian_full"
    },
    "info": {
      "properties": {
        "cookingTimeMinutes": {
          "type": "short"
        },
        "cost": {
          "type": "keyword"
        },
        "difficulty": {
          "enabled": False
        },
        "dosesForPersons": {
          "enabled": False
        },
        "note": {
          "type": "text",
          "analyzer": "italian_full"
        },
        "other": {
          "type": "text",
          "analyzer": "italian_full"
        },
        "preparationTimeMinutes": {
          "type": "text"
        }
      }
    },
    "link": {
      "type": "keyword"
    },
    "pageName": {
      "type": "keyword"
    }
  }
}

```

A sample query looks like this one:

```auto
     query = {
        "multi_match": {
          "query": "zucchero",
          "fields": [
            "title^3", "ingredients^2", "descriptionSections", "category",
          ]
        }
      }

      arguments = {}
      arguments["index"] = "recipes_it"
      arguments["query"] = query
      arguments["from_"] = 0
      arguments["size"] = 20

      retval = self._es.search(**arguments)

```

Search results are 0, when I search an ingredient name.  
If I search for a term in title, I get the correct number of results.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 26, 2024, 9:54am UTC](https://discuss.elastic.co/t/python-client-multisearch-with-different-fields-weights/354064/4 "2024-02-26T09:54:13Z")

</div>

Should the list of fields queried not be `"title^3", "ingredients.name^2", "descriptionSections.contents", "category"...` so you actually query the fields that are mapped as `text`?

---

<div class="post-metadata">

**Author:** ![Marco\_Solari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_solari/32/131794_2.png) [@Marco\_Solari](https://discuss.elastic.co/u/Marco_Solari)\
**Post date:** [February 26, 2024, 10:09am UTC](https://discuss.elastic.co/t/python-client-multisearch-with-different-fields-weights/354064/5 "2024-02-26T10:09:20Z")

</div>

Thanks! I did non know about that query usage... I did expect indicating an objecgt in the query would match the whole objecgt fields... Thanks again!  
The query correctly returns all the documents with that ingredient now.

One more suggestion: the only source of documentation for ES Python Client API is this one: "[https://elasticsearch-py.readthedocs.io/en/v8.12.1/](https://elasticsearch-py.readthedocs.io/en/v8.12.1/)", correct?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 26, 2024, 10:13am UTC](https://discuss.elastic.co/t/python-client-multisearch-with-different-fields-weights/354064/6 "2024-02-26T10:13:05Z")

</div>

> [@Marco\_Solari](#):
>
> One more suggestion: the only source of documentation for ES Python Client API is this one: "[Python Elasticsearch Client — Python Elasticsearch client 8.12.1 documentation](https://elasticsearch-py.readthedocs.io/en/v8.12.1/)", correct?

As not that familiar with the Python clinet so do not know. When it comes to determining the usage of different parameters I would recommend you also look at [the general docs for that query type](https://www.elastic.co/guide/en/elasticsearch/reference/8.12/query-dsl-multi-match-query.html).

---

<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 25, 2024, 10:13am UTC](https://discuss.elastic.co/t/python-client-multisearch-with-different-fields-weights/354064/7 "2024-03-25T10:13:26Z")

</div>

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