# How to search with correct stemming?

**URL:** https://discuss.elastic.co/t/how-to-search-with-correct-stemming/353388
**Category:** Elastic Search
**Tags:** elastic-app-search
**Created:** [February 15, 2024, 3:04pm UTC](https://discuss.elastic.co/t/how-to-search-with-correct-stemming/353388 "2024-02-15T15:04:54Z")
**Posts on this page:** 4
**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 15, 2024, 3:04pm UTC](https://discuss.elastic.co/t/how-to-search-with-correct-stemming/353388/1 "2024-02-15T15:04:54Z")

</div>

Sorry, I'm really new to elasticsearch...  
I'm trying basic functionalities...

I created my first index (to be used for italian language):

```auto
PUT index_it
{
  "settings": {
    "analysis": {
      "filter": {
        "italian_elision": {
          "type": "elision",
          "articles": [
            "c",
            "l",
            "all",
            "dall",
            "dell",
            "nell",
            "sull",
            "coll",
            "pell",
            "gl",
            "agl",
            "dagl",
            "degl",
            "negl",
            "sugl",
            "un",
            "m",
            "t",
            "s",
            "v",
            "d"
          ],
          "articles_case": true
        },
        "italian_stop": {
          "type": "stop",
          "stopwords": "_italian_"
        },
        "italian_keywords": {
          "type": "keyword_marker",
          "keywords": [
            "esempio"
          ]
        },
        "italian_stemmer": {
          "type": "stemmer",
          "language": "italian"
        }
      },
      "analyzer": {
        "italian_full": {
          "tokenizer": "standard",
          "filter": [
            "italian_elision",
            "lowercase",
            "italian_stop",
            "italian_keywords",
            "italian_stemmer"
          ]
        }
      }
    }
  }
}

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "index_it"
}

```

and put one word in index ("torta", Italian for "cake"):

```auto
PUT index_it/_doc/1
{
  "title": "torta"
}

{
  "_index": "index_it",
  "_id": "1",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}

```

If I analyze that word, I see it's correclty "stemmed" as "tort":

```auto
POST index_it/_analyze
{
  "analyzer": "italian_full",
  "text": "torta"
}

{
  "tokens": [
    {
      "token": "tort",
      "start_offset": 0,
      "end_offset": 5,
      "type": "<ALPHANUM>",
      "position": 0
    }
  ]
}

```

I'd expect to be able to search for both "torta" and "torte" (same word, plural).  
I can find the singular form, but not the plural... :-/

```auto
GET index_it/_search
{
  "query": {
    "match": {
      "title": "torta"
    }
  }
}

{
  "took": 6,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "index_it",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "title": "torta"
        }
      }
    ]
  }
}

```

But not "torte":

```auto
GET index_it/_search
{
  "query": {
    "simple_query_string": {
      "fields": ["title"],
      "query": "torte"
    }
  }
}

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  }
}

```

What do I miss? Shoul I specify the analizer in the queryes too?

---

<div class="post-metadata">

### Author: ![demjened](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/demjened/32/109159_2.png) [@demjened](https://discuss.elastic.co/u/demjened)
#### Post date: [February 15, 2024, 5:42pm UTC](https://discuss.elastic.co/t/how-to-search-with-correct-stemming/353388/2 "2024-02-15T17:42:30Z")

</div>

Hi Marco and welcome to the Elastic community!

You are on the right track, but in order for the `title` field to be analyzed with the `italian_full` analyzer (and support stemming in Italian), you need to explicitly specify that in the field's mapping when you create the index:

```auto
PUT index_it
{
  "settings": { ... }, // your settings as above
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "italian_full"
      }
    }
  }
}

```

This configures two things: 1. `title` will be analyzed with `italian_full`, rather than with the default analyzer, and 2. queries against `title` will also be analyzed with `italian_full`, so you can run searches in Italian.

```auto
PUT index_it/_doc/1
{
  "title": "torta"
}

GET index_it/_search
{
  "query": {
    "match": {
      "title": "torte"
    }
  }
}

{
...
    "hits": [
      {
        "_index": "index_it",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "title": "torta"
        }
      }
    ]
}

```

For more info, please check out [this guide](https://www.elastic.co/guide/en/elasticsearch/reference/current/specify-analyzer.html) on specifying an analyzer.

If you want the Italian analyzer to apply to multiple fields in the index by default (e.g. to all text fields), consider using an [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html).

---

<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 15, 2024, 8:27pm UTC](https://discuss.elastic.co/t/how-to-search-with-correct-stemming/353388/3 "2024-02-15T20:27:10Z")

</div>

Thank you so much! It works like a charm... 🙂 Wonderful!  
It's so nice too to enter such a viable and responsive community!

---

<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 14, 2024, 8:27pm UTC](https://discuss.elastic.co/t/how-to-search-with-correct-stemming/353388/4 "2024-03-14T20:27:38Z")

</div>

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