Prefix query not analyzed

Dear team,

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

PUT my-index
   "mappings": {
      "properties": {
         "title": {
            "type": "text",
            "analyzer": "standard",
            "fields": {
               "fr": {
                  "type": "text",
                  "analyzer": "french"
PUT my-index/_doc/1
   "title": "L'Homme n'est rien d'autre que son projet."
GET my-index/_search
   "query": {
      "prefix": {
         "": "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,



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.

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?


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

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