How can I fix this to suggest phrases after say, three characters have been entered?

My query
{
"suggest": {
"text" : "Tes",
"simple_phrase" : {
"phrase" : {
"field" : "Active_Substance_mstr.trigram",
"size" : 1,
"max_errors" : 6,
"direct_generator" : [ {
"field" : "Active_Substance_mstr.trigram",
"suggest_mode" : "always",
"min_word_length" : 1,
"max_edits" :"2"
} ],
"collate": {
"query": {
"source" : {
"match": {
"{{field_name}}" : "{{suggestion}}"
}
}
},
"params": {"field_name" : "title"},
"prune": true
}
}
}
}
}

Data:
{
"Active_Substance_mstr": "Test",
"Biomarker_mstr": "TestABC"
}
Result:

{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits":
},
"suggest": {
"simple_phrase": [
{
"text": "Tes",
"offset": 0,
"length": 3,
"options":
}
]
}
}

Welcome!

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Have a look at the Elastic Stack and Solutions Help · Forums and Slack | Elastic page. It contains also lot of useful information on how to ask for help.

Also please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.

Hi !

Thanks for your response..

I am trying to implement Phrase suggester in my project to achieve autocomplete functionality. Below is the problem I am facing.
I am searching for 'BGM' I should get 'BGM67' as my result, however its not happening. Suppose if I have a word 'Product' and If I type prod then product and other suggestions that starts with prod should get listed, how can I achieve it ? (default max edit is set to 2, is this the reason that product is not listed). But after typing 'Produ' I am getting 'Product' in the suggestion list.

In other post I checked on how to implement Phrase suggester functionality using elastic.clients.elasticsearch .net client as I did not find reference.

Could you please help?

Please let me know if you need any further details....

Please provide a full recreation script as I mentioned earlier. That would help.

Otherwise, please have a look at this resource which could help:

Hi, Good Morning..

Below here is what I am trying to achieve...

I am trying to create an index 'dpa_suggestormultifield' in Elasticsearch with the below mappings for field 'Active_Substance_mstr'

PUT/ http://localhost:9200/dpa_suggestormultifield
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "analysis": {
        "analyzer": {
          "trigram": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["lowercase","shingle"]
          }
         
        },
        "filter": {
          "shingle": {
            "type": "shingle",
            "min_shingle_size": 2,
            "max_shingle_size": 3
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "Active_Substance_mstr": {
        "type": "text",
        "fields": {
          "trigram": {
            "type": "text",
            "analyzer": "trigram"
          }
        }
      }
    }
  }
}

Below is the data I am inserting into my index.

POST/ http://localhost:9200/dpa_suggestormultifield/_bulk
 {
        "Active_Substance_mstr": "rurioctocog alfa pegol"
    }
    {
        "Active_Substance_mstr": "tenofovir disoproxil"
    }
    {
        "Active_Substance_mstr": "trastuzumad"
    }
     {
        "Active_Substance_mstr": "CHLOROPROCAINE HYDROCHLORIDE"
    }
    {
      "Active_Substance_mstr": "trastuzumad"
     }
        {
        "Active_Substance_mstr": "The Vaccines and Related Biological Product"
    }
      {
        "Active_Substance_mstr": "BGMQ2"
    }
    {
        "Active_Substance_mstr": "Test"
    }
    
    {
        "Active_Substance_mstr": "tar-ausguide20110608bio"
    }

After data insert I am trying to get suggestions using phrase suggester with text 'prod' I didn't get matching results because of max_edits is defaluts to 2.

GET/ http://localhost:9200/dpa_suggestormultifield/_search
{
  "suggest": {
    "text" : "prod",
    "simple_phrase" : {
      "phrase" : {
        "field" :  "Active_Substance_mstr.trigram",
        "size" :   1,
        "direct_generator" : [ {
          "field" :            "Active_Substance_mstr.trigram",
          "suggest_mode" :     "always",
          "min_word_length" :  1
        } ]

        }
      }
    }
  }

However if I try to search with 'Produ' I get the results. Below is the response.

{
    "took": 61,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "suggest": {
        "simple_phrase": [
            {
                "text": "Produ",
                "offset": 0,
                "length": 5,
                "options": [
                    {
                        "text": "product",
                        "score": 0.21575698
                    }
                ]
            }
        ]
    }
}

My question here is how to get results even if I search with 'prod' - I should get results as 'product' using phrase suggester

Please let me know if you need further details.

Sorry @dadoonet , Search as you type doesn't suits our requirement that's the reason we are going ahead with phrase suggester for autocomplete functionality.

Above is the query and results we are trying to achieve in .NET, dummy data is used for development purpose.

Also, could you please help me to implement Phrase suggester in .NET Core using elastic.clients.elasticsearch library?

No sorry. I can't. I'm not a dotnet dev.

@dadoonet , Could you help me with this, can this be achievable?

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