Help me in searching hyphen contains parts

(Phani Nadiminti) #1

Hi All,

I am working on Searching parts in elasticsearch I have elasticsearch version 5.1.1 with me.the index has contains partNumbers which has values like 044-1215S etc.. and mostly it contains dots and special characters. I have built the following analyzer for this to support the criteria

PUT /test
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"ngram_filter": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 20
"analyzer": {
"ngram_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"mappings": {
"properties": {
"type": "text",
"analyzer": "ngram_analyzer",
"search_analyzer": "standard"

  • All my partial matches working.
  • but term queries not working with hyphen it is considering at all when i checked analyzer .

can a term query will work on this ? is there any special analyzers which can work with all most of the special characters that lucene allowed.

Thanks in advance

(Russ Cam) #2

A term query can work with this, but a term query input does not undergo analysis, so the search query input will be querying against input that has been analyzed at index time with the ngram_analyzer.

What perhaps you may want to do is map partNumber as a multi_field where one field uses the ngram_analyzer to support partial matches, and another field is mapped as a keyword type, to support verbatim matches.

(Phani Nadiminti) #3

Hi ,

Thank you for the suggestions yes this way i will try . and one more doubt is there any flexibility to search words like (hyphen contained parts ) 45-5 in part 4558945-563 can we form tokenize or methods to make the above search please advice.

(system) #4

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