# Question about reindexing everything due to incorrect Mapping

**URL:** <https://discuss.elastic.co/t/question-about-reindexing-everything-due-to-incorrect-mapping/11370>\
**Category:** Elasticsearch\
**Created:** [March 29, 2013, 1:17am UTC](https://discuss.elastic.co/t/question-about-reindexing-everything-due-to-incorrect-mapping/11370 "2013-03-29T01:17:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fish\_Tastic](https://avatars.discourse-cdn.com/v4/letter/f/4bbf92/32.png) [@Fish\_Tastic](https://discuss.elastic.co/u/Fish_Tastic)\
**Post date:** [March 29, 2013, 1:17am UTC](https://discuss.elastic.co/t/question-about-reindexing-everything-due-to-incorrect-mapping/11370/1 "2013-03-29T01:17:04Z")

</div>

Hi,

I will start with what happened first before listing out the questions.

I started by indexing a bunch of data. Each data type (a fish) has a name  
and a type.

curl -XPUT '[http://localhost:9200/animal/fish/1](http://localhost:9200/animal/fish/1)' -d '{"name" : "channel cat  
fish", "type" : "cat-fish"}'

curl -XPUT '[http://localhost:9200/animal/fish/2](http://localhost:9200/animal/fish/2)' -d '{"name" : "blue cat  
fish", "type" : "cat-fish"}'

curl -XPUT '[http://localhost:9200/animal/fish/3](http://localhost:9200/animal/fish/3)' -d '{"name" : "atlantic  
salmon", "type" : "salmon"}'

curl -XPUT '[http://localhost:9200/animal/fish/4](http://localhost:9200/animal/fish/4)' -d '{"name" : "blue  
salmon", "type" : "salmon"}'

curl -XPUT '[http://localhost:9200/animal/fish/5](http://localhost:9200/animal/fish/5)' -d '{"name" : "blue carp",  
"type" : "carp"}'

Now I would like to search for fish that contains "blue" but must be either  
a "cat-fish" or a "salmon". So I follow the guide and build myself a  
filtered query. I want it to return "blue cat fish" and "blue salmon"

curl -XGET '[http://localhost:9200/animal/fish/\_search?pretty=true](http://localhost:9200/animal/fish/_search?pretty=true)' -d  
'{  
"query": {  
"filtered" : {  
"query" : {  
"match" : { "\_all" : "blue" }  
},  
"filter" : {  
"bool" : {  
"should" : {  
"term": {"type" : "salmon"}  
},  
"should" : {  
"term": {"type" : "cat-fish"}  
}  
}  
}  
}  
}  
}'

However, it only returns "blue salmon", its fails to return "blue cat  
fish". I check the documentation and find that "cat-fish" was processed  
using the standard analyzer and it was tokenized before being indexed. So  
searching directly with term filter doesn't work.

I realized that I have to changed the mapping, specifically adding "index:  
not\_analyzed" to "type". So I delete everything that was indexed, set the  
mapping, insert everything back. Now the search works great.

curl -XDELETE '[http://localhost:9200/animal/fish/](http://localhost:9200/animal/fish/)'

curl -XPUT '[http://localhost:9200/animal/fish/\_mapping](http://localhost:9200/animal/fish/_mapping)' -d '{  
"fish" : {  
"properties" : {  
"name" : { "type" : "string" },  
"type" : { "type" : "string", "index" : "not\_analyzed"}  
}  
}  
}'

My questions

- Would it be possible to perform the same filtering without changing  
the mapping? Say ... using a different query.
- If I must change the mapping, is it possible to change the mapping  
without deleting everything first? e.g. update a field to "not\_analyzed"  
without deleting and reindexing everything.
- If I maintain mapping, would it be better to use something like  
spring-elasticsearch or just client.admin().indices().preparePutMapping?

Thanks! Any help would be appreciated.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [March 29, 2013, 5:46am UTC](https://discuss.elastic.co/t/question-about-reindexing-everything-due-to-incorrect-mapping/11370/2 "2013-03-29T05:46:21Z")

</div>

Hi,  
To answer your questions:

- Would it be possible to perform the same filtering without changing  
the mapping? Say ... using a different query.

Not in any sane way. If your data set is extremely small you could wrap all  
the terms in wild cards _cat_ _fish_ but this will match substrings and is  
extremely discouraged. I hope people don't think badly of me for even  
mentioning it.

- If I must change the mapping, is it possible to change the mapping  
without deleting everything first? e.g. update a field to "not\_analyzed"  
without deleting and reindexing everything.

Do not fear re-indexing as your data model changes it will be a necessity.  
It also generates a clean defragmented index. You should use index aliasing  
to avoid having to delete, re-create, re-index. Instead re-index to new  
index with new mappings, swap alias, delete old index. There are plugins to  
help with the re-index  
process: [GitHub - karussell/elasticsearch-reindex: Simple re-indexing. To backup, apply index settings changes and more ElasticMagic](https://github.com/karussell/elasticsearch-reindex)

- If I maintain mapping, would it be better to use something like  
spring-elasticsearch or just client.admin().indices().preparePutMapping?

Sorry, can't really give a valid comparison. I have a Java app that talks  
to elasticsearch that pulls index settings and applies them with the Java  
AP(preparePutMapping)I, haven't used the spring integration.

Best Regards,  
Paul

On Thursday, March 28, 2013 7:17:04 PM UTC-6, Fish Tastic wrote:

> Hi,
> 
> I will start with what happened first before listing out the questions.
> 
> I started by indexing a bunch of data. Each data type (a fish) has a name  
> and a type.
> 
> curl -XPUT '[http://localhost:9200/animal/fish/1](http://localhost:9200/animal/fish/1)' -d '{"name" : "channel  
> cat fish", "type" : "cat-fish"}'
> 
> curl -XPUT '[http://localhost:9200/animal/fish/2](http://localhost:9200/animal/fish/2)' -d '{"name" : "blue cat  
> fish", "type" : "cat-fish"}'
> 
> curl -XPUT '[http://localhost:9200/animal/fish/3](http://localhost:9200/animal/fish/3)' -d '{"name" : "atlantic  
> salmon", "type" : "salmon"}'
> 
> curl -XPUT '[http://localhost:9200/animal/fish/4](http://localhost:9200/animal/fish/4)' -d '{"name" : "blue  
> salmon", "type" : "salmon"}'
> 
> curl -XPUT '[http://localhost:9200/animal/fish/5](http://localhost:9200/animal/fish/5)' -d '{"name" : "blue  
> carp", "type" : "carp"}'
> 
> Now I would like to search for fish that contains "blue" but must be  
> either a "cat-fish" or a "salmon". So I follow the guide and build myself a  
> filtered query. I want it to return "blue cat fish" and "blue salmon"
> 
> curl -XGET '[http://localhost:9200/animal/fish/\_search?pretty=true](http://localhost:9200/animal/fish/_search?pretty=true)' -d  
> '{  
> "query": {  
> "filtered" : {  
> "query" : {  
> "match" : { "\_all" : "blue" }  
> },  
> "filter" : {  
> "bool" : {  
> "should" : {  
> "term": {"type" : "salmon"}  
> },  
> "should" : {  
> "term": {"type" : "cat-fish"}  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> However, it only returns "blue salmon", its fails to return "blue cat  
> fish". I check the documentation and find that "cat-fish" was processed  
> using the standard analyzer and it was tokenized before being indexed. So  
> searching directly with term filter doesn't work.
> 
> I realized that I have to changed the mapping, specifically adding "index:  
> not\_analyzed" to "type". So I delete everything that was indexed, set the  
> mapping, insert everything back. Now the search works great.
> 
> curl -XDELETE '[http://localhost:9200/animal/fish/](http://localhost:9200/animal/fish/)'
> 
> curl -XPUT '[http://localhost:9200/animal/fish/\_mapping](http://localhost:9200/animal/fish/_mapping)' -d '{  
> "fish" : {  
> "properties" : {  
> "name" : { "type" : "string" },  
> "type" : { "type" : "string", "index" : "not\_analyzed"}  
> }  
> }  
> }'
> 
> My questions
> 
> - Would it be possible to perform the same filtering without changing  
> the mapping? Say ... using a different query.
> - If I must change the mapping, is it possible to change the mapping  
> without deleting everything first? e.g. update a field to "not\_analyzed"  
> without deleting and reindexing everything.
> - If I maintain mapping, would it be better to use something like  
> spring-elasticsearch or just client.admin().indices().  
> preparePutMapping?
> 
> Thanks! Any help would be appreciated.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Fish\_Tastic](https://avatars.discourse-cdn.com/v4/letter/f/4bbf92/32.png) [@Fish\_Tastic](https://discuss.elastic.co/u/Fish_Tastic)\
**Post date:** [March 29, 2013, 7:54pm UTC](https://discuss.elastic.co/t/question-about-reindexing-everything-due-to-incorrect-mapping/11370/3 "2013-03-29T19:54:21Z")

</div>

Hi Paul, that answers all my questions! Thank you very much.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:43am UTC](https://discuss.elastic.co/t/question-about-reindexing-everything-due-to-incorrect-mapping/11370/4 "2017-07-06T02:43:32Z")

</div>


