# Help - custom anaylzer almost works but not getting the results I want when searching \_all

**URL:** <https://discuss.elastic.co/t/help-custom-anaylzer-almost-works-but-not-getting-the-results-i-want-when-searching--all/9459>\
**Category:** Elasticsearch\
**Created:** [October 24, 2012, 3:54pm UTC](https://discuss.elastic.co/t/help-custom-anaylzer-almost-works-but-not-getting-the-results-i-want-when-searching--all/9459 "2012-10-24T15:54:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NLS](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@NLS](https://discuss.elastic.co/u/NLS)\
**Post date:** [October 24, 2012, 3:54pm UTC](https://discuss.elastic.co/t/help-custom-anaylzer-almost-works-but-not-getting-the-results-i-want-when-searching--all/9459/1 "2012-10-24T15:54:55Z")

</div>

I got elastic search up and running and indexing but I do not want it to  
tokenize the dash out. So I searched around and wrote a custom analyzer.  
This works but I want it to be the default for all indices and types but  
can't seem to get that going.

Anyway, I created a new index with command:

PUT [http://myhost:9200/new\_index](http://myhost:9200/new_index)  
{  
"settings":{  
"index":{  
"analysis":{  
"analyzer":{  
"s2i\_analyzer":{  
"type":"custom",  
"tokenizer":"keyword",  
"filter":[  
"word\_filter",  
"lowercase"  
]  
}  
},  
"filter":{  
"word\_filter":{  
"type":"word\_delimiter",  
"generate\_word\_parts":"false",  
"generate\_number\_parts":"false",  
"split\_on\_numerics":"false",  
"split\_on\_case\_change":"false",  
"preserve\_original":"true"  
}  
}  
}  
}  
}  
}

That works, then I can successfully, set that analyzer on a type's field by  
doing command  
PUT [http://myhost:9200/new\_index/new\_type/\_mapping](http://myhost:9200/new_index/new_type/_mapping)  
{  
"new\_type":{  
"properties":{  
"alias":{  
"type":"string",  
"index\_analyzer":"s2i\_analyzer",  
"search\_analyzer":"s2i\_analyzer"  
},  
"modelName":{  
"type":"string",  
"index\_analyzer":"s2i\_analyzer",  
"search\_analyzer":"s2i\_analyzer"  
},  
"\_all":{  
"type":"string",  
"index\_analyzer":"s2i\_analyzer",  
"search\_analyzer":"s2i\_analyzer"  
}  
}  
}  
}  
That works successfully.

I successfully query using query\_string and get the correct results I  
expect on fields modelName and alias.  
HOWEVER, the same query but change the field name to \_all, returns NO  
RESULTS. I don't understand.  
I have a modelName "Owner\_at\_1-1tenth\_Boxes".

I can query with query\_string Owner\_at\_1-1\* and it works when using field  
modelName but not \_all.  
I can query with query\_string Owner\* and it works for both field modelName  
and \_all

So how do I make the default analyzer for both index and search be the  
s2i\_analyzer for ALL FIELDS so the dash is handled the way we want.

I have been search the forum and web and found that to set the default, it  
should be index.analysis.analyzer.default.type. So I tried many times to  
add it to either the settings on index creation and  
I tried to add it to the mapping on the type.

BUT I got errors or it did not work. So can you please try me whether I  
should:

1. It needs to be done on index creation or type mapping?
2. What is the exact json that I add to my stuff?

Thanks in advance.

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [October 24, 2012, 5:25pm UTC](https://discuss.elastic.co/t/help-custom-anaylzer-almost-works-but-not-getting-the-results-i-want-when-searching--all/9459/2 "2012-10-24T17:25:55Z")

</div>

If you want to use this analyzer for all fields, you can simply define it  
as default analyzer:

curl -XPUT [http://localhost:9200/new\_index](http://localhost:9200/new_index) -d '{  
"settings":{  
"index":{  
"analysis":{  
"analyzer":{  
"_default_":{  
"type":"custom",  
"tokenizer":"keyword",  
"filter":[  
"word\_filter",  
"lowercase"  
]  
}  
},  
"filter":{  
"word\_filter":{  
"type":"word\_delimiter",  
"generate\_word\_parts":"false",  
"generate\_number\_parts":"false",  
"split\_on\_numerics":"false",  
"split\_on\_case\_change":"false",  
"preserve\_original":"true"  
}  
}  
}  
}  
}  
}'

This way, you will not have to apply it explicitly for every single field.

On Wednesday, October 24, 2012 11:54:55 AM UTC-4, njl wrote:

> I got Elasticsearch up and running and indexing but I do not want it to  
> tokenize the dash out. So I searched around and wrote a custom analyzer.  
> This works but I want it to be the default for all indices and types but  
> can't seem to get that going.
> 
> Anyway, I created a new index with command:
> 
> PUT [http://myhost:9200/new\_index](http://myhost:9200/new_index)  
> {  
> "settings":{  
> "index":{  
> "analysis":{  
> "analyzer":{  
> "s2i\_analyzer":{  
> "type":"custom",  
> "tokenizer":"keyword",  
> "filter":[  
> "word\_filter",  
> "lowercase"  
> ]  
> }  
> },  
> "filter":{  
> "word\_filter":{  
> "type":"word\_delimiter",  
> "generate\_word\_parts":"false",  
> "generate\_number\_parts":"false",  
> "split\_on\_numerics":"false",  
> "split\_on\_case\_change":"false",  
> "preserve\_original":"true"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> That works, then I can successfully, set that analyzer on a type's field  
> by doing command  
> PUT [http://myhost:9200/new\_index/new\_type/\_mapping](http://myhost:9200/new_index/new_type/_mapping)  
> {  
> "new\_type":{  
> "properties":{  
> "alias":{  
> "type":"string",  
> "index\_analyzer":"s2i\_analyzer",  
> "search\_analyzer":"s2i\_analyzer"  
> },  
> "modelName":{  
> "type":"string",  
> "index\_analyzer":"s2i\_analyzer",  
> "search\_analyzer":"s2i\_analyzer"  
> },  
> "\_all":{  
> "type":"string",  
> "index\_analyzer":"s2i\_analyzer",  
> "search\_analyzer":"s2i\_analyzer"  
> }  
> }  
> }  
> }  
> That works successfully.
> 
> I successfully query using query\_string and get the correct results I  
> expect on fields modelName and alias.  
> HOWEVER, the same query but change the field name to \_all, returns NO  
> RESULTS. I don't understand.  
> I have a modelName "Owner\_at\_1-1tenth\_Boxes".
> 
> I can query with query\_string Owner\_at\_1-1\* and it works when using field  
> modelName but not \_all.  
> I can query with query\_string Owner\* and it works for both field  
> modelName and \_all
> 
> So how do I make the default analyzer for both index and search be the  
> s2i\_analyzer for ALL FIELDS so the dash is handled the way we want.
> 
> I have been search the forum and web and found that to set the default, it  
> should be index.analysis.analyzer.default.type. So I tried many times to  
> add it to either the settings on index creation and  
> I tried to add it to the mapping on the type.
> 
> BUT I got errors or it did not work. So can you please try me whether I  
> should:
> 
> 1. It needs to be done on index creation or type mapping?
> 2. What is the exact json that I add to my stuff?
> 
> Thanks in advance.

--

---

<div class="post-metadata">

**Author:** ![NLS](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@NLS](https://discuss.elastic.co/u/NLS)\
**Post date:** [October 24, 2012, 5:29pm UTC](https://discuss.elastic.co/t/help-custom-anaylzer-almost-works-but-not-getting-the-results-i-want-when-searching--all/9459/3 "2012-10-24T17:29:46Z")

</div>

Thanks

From: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
[[mailto:elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)] On Behalf Of Igor Motov  
Sent: Wednesday, October 24, 2012 1:26 PM  
To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)  
Subject: Re: Help - custom anaylzer almost works but not getting the  
results I want when searching \_all

If you want to use this analyzer for all fields, you can simply define  
it as default analyzer:

curl -XPUT [http://localhost:9200/new\_index](http://localhost:9200/new_index) -d '{

"settings":{

```
  "index":{

     "analysis":{

        "analyzer":{

           "default":{

              "type":"custom",

              "tokenizer":"keyword",

              "filter":[

                 "word_filter",

                 "lowercase"

              ]

           }

        },

        "filter":{

           "word_filter":{

              "type":"word_delimiter",

              "generate_word_parts":"false",

              "generate_number_parts":"false",

              "split_on_numerics":"false",

              "split_on_case_change":"false",

              "preserve_original":"true"

           }

        }

     }

  }

```

}

}'

This way, you will not have to apply it explicitly for every single  
field.

On Wednesday, October 24, 2012 11:54:55 AM UTC-4, njl wrote:

I got elastic search up and running and indexing but I do not want it to  
tokenize the dash out. So I searched around and wrote a custom  
analyzer.

This works but I want it to be the default for all indices and types but  
can't seem to get that going.

Anyway, I created a new index with command:

PUT [http://myhost:9200/new\_index](http://myhost:9200/new_index)

{

"settings":{

```
  "index":{

     "analysis":{

        "analyzer":{

           "s2i_analyzer":{

              "type":"custom",

              "tokenizer":"keyword",

              "filter":[

                 "word_filter",

                 "lowercase"

              ]

           }

        },

        "filter":{

           "word_filter":{

              "type":"word_delimiter",

              "generate_word_parts":"false",

              "generate_number_parts":"false",

              "split_on_numerics":"false",

              "split_on_case_change":"false",

              "preserve_original":"true"

           }

        }

     }

  }

```

}

}

That works, then I can successfully, set that analyzer on a type's field  
by doing command

PUT [http://myhost:9200/new\_index/new\_type/\_mapping](http://myhost:9200/new_index/new_type/_mapping)

{

"new\_type":{

```
  "properties":{

     "alias":{

        "type":"string",

        "index_analyzer":"s2i_analyzer",

        "search_analyzer":"s2i_analyzer"

     },

     "modelName":{

        "type":"string",

        "index_analyzer":"s2i_analyzer",

        "search_analyzer":"s2i_analyzer"

     },

     "_all":{

        "type":"string",

        "index_analyzer":"s2i_analyzer",

        "search_analyzer":"s2i_analyzer"

     }

  }

```

}

}

That works successfully.

I successfully query using query\_string and get the correct results I  
expect on fields modelName and alias.

HOWEVER, the same query but change the field name to \_all, returns NO  
RESULTS. I don't understand.  
I have a modelName "Owner\_at\_1-1tenth\_Boxes".

I can query with query\_string Owner\_at\_1-1\* and it works when using  
field modelName but not \_all.

I can query with query\_string Owner\* and it works for both field  
modelName and \_all

So how do I make the default analyzer for both index and search be the  
s2i\_analyzer for ALL FIELDS so the dash is handled the way we want.

I have been search the forum and web and found that to set the default,  
it should be index.analysis.analyzer.default.type. So I tried many  
times to add it to either the settings on index creation and

I tried to add it to the mapping on the type.

BUT I got errors or it did not work. So can you please try me whether  
I should:

1. It needs to be done on index creation or type mapping?

2. What is the exact json that I add to my stuff?

Thanks in advance.

--

--

---

<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:** [July 6, 2017, 3:07am UTC](https://discuss.elastic.co/t/help-custom-anaylzer-almost-works-but-not-getting-the-results-i-want-when-searching--all/9459/4 "2017-07-06T03:07:24Z")

</div>


