# Prefix query not analyzed

**URL:** <https://discuss.elastic.co/t/prefix-query-not-analyzed/257901>\
**Category:** Elasticsearch\
**Created:** [December 7, 2020, 7:25pm UTC](https://discuss.elastic.co/t/prefix-query-not-analyzed/257901 "2020-12-07T19:25:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davide-martins](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@davide-martins](https://discuss.elastic.co/u/davide-martins)\
**Post date:** [December 7, 2020, 7:25pm UTC](https://discuss.elastic.co/t/prefix-query-not-analyzed/257901/1 "2020-12-07T19:25:51Z")

</div>

Dear team,

I'm trying to setup a query that contain a specific prefix in a provided text (not a keyword).

```auto
PUT my-index
{
   "mappings": {
      "properties": {
         "title": {
            "type": "text",
            "analyzer": "standard",
            "fields": {
               "fr": {
                  "type": "text",
                  "analyzer": "french"
               }
            }
         }
      }
   }
}

```

```auto
PUT my-index/_doc/1
{
   "title": "L'Homme n'est rien d'autre que son projet."
}

```

```auto
GET my-index/_search
{
   "query": {
      "prefix": {
         "title.fr": "hom"
      }
   }
}

```

This query must return the document with id: 1 (if the prefix query was analyzed).  
**As documented, prefix query is not analyzed, why such behavior?**

At the moment, I'm creating a custom analyzer which inherits from _language analyzer_ (same tokenizer, char\_filter and filter) to which I add a _edge\_gram filter_.  
Then I can perform a match query with this custom analyzer. Moreover I can use multi\_match query.  
**Is this solution correct? What do you advise me?**

Best regards,

Davide MARTINS

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 7, 2020, 7:39pm UTC](https://discuss.elastic.co/t/prefix-query-not-analyzed/257901/2 "2020-12-07T19:39:37Z")

</div>

Welcome!

Your solution looks good to me.  
I'd probably index the same text with `french` analyzer and your custom analyzer as a fallback.

At query time, I'd boost on the `french` field.  
So if it matches on full terms, the score will be higher.

---

<div class="post-metadata">

**Author:** ![davide-martins](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@davide-martins](https://discuss.elastic.co/u/davide-martins)\
**Post date:** [December 7, 2020, 7:48pm UTC](https://discuss.elastic.co/t/prefix-query-not-analyzed/257901/3 "2020-12-07T19:48:06Z")

</div>

Thank you!

I'm planning to use the _custom_ analyzer at index time and the _french_ one at search time.

Indeed you had a good idea. I want to match first the documents with french tokens instead the ones with edge\_gram.

Regarding the performances, do I need to enable specific parameters at index time and/or search time?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 9, 2020, 3:11pm UTC](https://discuss.elastic.co/t/prefix-query-not-analyzed/257901/4 "2020-12-09T15:11:31Z")

</div>

> [@davide-martins](#):
>
> Regarding the performances, do I need to enable specific parameters at index time and/or search time?

No.

BTW I wrote an example a long time ago of some combinations you could do. I hope this could help:

> <https://gist.github.com/dadoonet/5179ee72ecbf08f12f53d4bda1b76bab>

---

<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:** [January 6, 2021, 3:11pm UTC](https://discuss.elastic.co/t/prefix-query-not-analyzed/257901/5 "2021-01-06T15:11:58Z")

</div>

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