# Search sort using a field with an "index\_name" results in "No mapping found"

**URL:** <https://discuss.elastic.co/t/search-sort-using-a-field-with-an-index-name-results-in-no-mapping-found/21224>\
**Category:** Elasticsearch\
**Created:** [December 12, 2014, 12:12am UTC](https://discuss.elastic.co/t/search-sort-using-a-field-with-an-index-name-results-in-no-mapping-found/21224 "2014-12-12T00:12:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Reed](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Dave\_Reed](https://discuss.elastic.co/u/Dave_Reed)\
**Post date:** [December 12, 2014, 12:12am UTC](https://discuss.elastic.co/t/search-sort-using-a-field-with-an-index-name-results-in-no-mapping-found/21224/1 "2014-12-12T00:12:10Z")

</div>

I ran into this problem, and discovered this StackOverflow post (with no  
answer):

> <https://stackoverflow.com/questions/23348172/elasticsearch-index-name-with-multi-field>

That original poster included a gist that reproduces it quite nicely  
(confirmed on 1.4.1):

> <https://gist.github.com/pmishev/11375297>

Partially replicated here for convenience (see the link for full curl steps  
to reproduce):

# Create mapping

curl -XPOST localhost:9200/index1/ -d '{  
"mappings": {  
"people": {  
"properties": {  
"work\_email": {  
"type": "string",  
"index\_name": "email",  
"fields": {  
"raw": {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
}  
}  
}  
}'

Basically, I have an analyzed string field and a non-analyzed version of it  
so that I can sort by it. But instead of sorting by "field.sort" or  
"field.raw", I need to use "field\_sort", basically for back compat reasons.  
To accomplish that I tried giving the non-analyzed sortable version of the  
string field an index\_name. But trying to sort using the given index\_name  
results in an error: "No mapping found for [field\_sort] in order to sort  
on".

The gist referenced above is slightly different than I am explaining,  
because it puts the "index\_name" on the parent field instead of the sorted  
part, but the result is the same.

To put it simply, it seems that you cannot sort by a field by its  
index\_name, you have to use the full path to it, which is a problem for me.  
Is this expected? Why should I be able to search for a field by its  
index\_name but not sort by it -- that seems unintended. Am I doing it  
wrong? Is there a better way to accomplish the same thing?

Thanks for the help!

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/af25ab54-407b-4e58-95ea-94c12fb3fb65%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/af25ab54-407b-4e58-95ea-94c12fb3fb65%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 12, 2014, 6:11am UTC](https://discuss.elastic.co/t/search-sort-using-a-field-with-an-index-name-results-in-no-mapping-found/21224/2 "2014-12-12T06:11:47Z")

</div>

What happen if you try:

"mappings": {  
"people": {  
"properties": {  
"work\_email": {  
"type": "string",  
"index\_name": "email",  
"fields": {  
"raw": {  
"type": "string",  
"index\_name": "email.raw",  
"index": "not\_analyzed"  
}  
}  
}  
}  
}  
}  
}'

Does this work?

David

> Le 12 déc. 2014 à 01:12, Dave Reed [infinity88@gmail.com](mailto:infinity88@gmail.com) a écrit :
> 
> I ran into this problem, and discovered this StackOverflow post (with no answer):  
> [elasticsearch index\_name with multi\_field - Stack Overflow](http://stackoverflow.com/questions/23348172/elasticsearch-index-name-with-multi-field)
> 
> That original poster included a gist that reproduces it quite nicely (confirmed on 1.4.1):  
> [sorting\_by\_aliased\_field.sh · GitHub](https://gist.github.com/pmishev/11375297)
> 
> Partially replicated here for convenience (see the link for full curl steps to reproduce):
> 
> # Create mapping
> 
> curl -XPOST localhost:9200/index1/ -d '{  
> "mappings": {  
> "people": {  
> "properties": {  
> "work\_email": {  
> "type": "string",  
> "index\_name": "email",  
> "fields": {  
> "raw": {  
> "type": "string",  
> "index": "not\_analyzed"  
> }  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> Basically, I have an analyzed string field and a non-analyzed version of it so that I can sort by it. But instead of sorting by "field.sort" or "field.raw", I need to use "field\_sort", basically for back compat reasons. To accomplish that I tried giving the non-analyzed sortable version of the string field an index\_name. But trying to sort using the given index\_name results in an error: "No mapping found for [field\_sort] in order to sort on".
> 
> The gist referenced above is slightly different than I am explaining, because it puts the "index\_name" on the parent field instead of the sorted part, but the result is the same.
> 
> To put it simply, it seems that you cannot sort by a field by its index\_name, you have to use the full path to it, which is a problem for me. Is this expected? Why should I be able to search for a field by its index\_name but not sort by it -- that seems unintended. Am I doing it wrong? Is there a better way to accomplish the same thing?
> 
> Thanks for the help!
> 
> --  
> 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).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/af25ab54-407b-4e58-95ea-94c12fb3fb65%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/af25ab54-407b-4e58-95ea-94c12fb3fb65%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3887D2C8-924B-40C5-94E0-5CFEEA98436A%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/3887D2C8-924B-40C5-94E0-5CFEEA98436A%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Dave\_Reed](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Dave\_Reed](https://discuss.elastic.co/u/Dave_Reed)\
**Post date:** [December 15, 2014, 5:41pm UTC](https://discuss.elastic.co/t/search-sort-using-a-field-with-an-index-name-results-in-no-mapping-found/21224/3 "2014-12-15T17:41:01Z")

</div>

I see you tried adding index\_name to the inner field as well. Nope, I'm  
afraid that did not work.

Anyone have any thoughts here? This definitely seems like a bug 🙂

On Thursday, December 11, 2014 10:12:02 PM UTC-8, David Pilato wrote:

> What happen if you try:
> 
> "mappings": {  
> "people": {  
> "properties": {  
> "work\_email": {  
> "type": "string",  
> "index\_name": "email",  
> "fields": {  
> "raw": {  
> "type": "string",  
> "index\_name": "email.raw",  
> "index": "not\_analyzed"  
> }  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> Does this work?
> 
> David
> 
> Le 12 déc. 2014 à 01:12, Dave Reed \<[infin...@gmail.com](mailto:infin...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> I ran into this problem, and discovered this StackOverflow post (with no  
> answer):
> 
> [elasticsearch index\_name with multi\_field - Stack Overflow](http://stackoverflow.com/questions/23348172/elasticsearch-index-name-with-multi-field)
> 
> That original poster included a gist that reproduces it quite nicely  
> (confirmed on 1.4.1):  
> [sorting\_by\_aliased\_field.sh · GitHub](https://gist.github.com/pmishev/11375297)
> 
> Partially replicated here for convenience (see the link for full curl  
> steps to reproduce):
> 
> # Create mapping
> 
> curl -XPOST localhost:9200/index1/ -d '{  
> "mappings": {  
> "people": {  
> "properties": {  
> "work\_email": {  
> "type": "string",  
> "index\_name": "email",  
> "fields": {  
> "raw": {  
> "type": "string",  
> "index": "not\_analyzed"  
> }  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> Basically, I have an analyzed string field and a non-analyzed version of  
> it so that I can sort by it. But instead of sorting by "field.sort" or  
> "field.raw", I need to use "field\_sort", basically for back compat reasons.  
> To accomplish that I tried giving the non-analyzed sortable version of the  
> string field an index\_name. But trying to sort using the given index\_name  
> results in an error: "No mapping found for [field\_sort] in order to sort  
> on".
> 
> The gist referenced above is slightly different than I am explaining,  
> because it puts the "index\_name" on the parent field instead of the sorted  
> part, but the result is the same.
> 
> To put it simply, it seems that you cannot sort by a field by its  
> index\_name, you have to use the full path to it, which is a problem for me.  
> Is this expected? Why should I be able to search for a field by its  
> index\_name but not sort by it -- that seems unintended. Am I doing it  
> wrong? Is there a better way to accomplish the same thing?
> 
> Thanks for the help!
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/af25ab54-407b-4e58-95ea-94c12fb3fb65%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/af25ab54-407b-4e58-95ea-94c12fb3fb65%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/af25ab54-407b-4e58-95ea-94c12fb3fb65%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/af25ab54-407b-4e58-95ea-94c12fb3fb65%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/71f2a195-b6b1-4666-93df-517603d568ea%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71f2a195-b6b1-4666-93df-517603d568ea%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Dave\_Reed](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Dave\_Reed](https://discuss.elastic.co/u/Dave_Reed)\
**Post date:** [December 17, 2014, 2:39am UTC](https://discuss.elastic.co/t/search-sort-using-a-field-with-an-index-name-results-in-no-mapping-found/21224/4 "2014-12-17T02:39:53Z")

</div>

Just in the interest of having a two-way link, I opened a github issue  
about it here:

> <https://github.com/elastic/elasticsearch/issues/8980>
>
> If you try to sort by "fieldname", and "fieldname" is the name of a mapped field… as specified by "index\_name", you get parse error stating that no mapping was found for that field. It doesn't seem right that you can search by the index\_name but not sort by it, hence this bug. Without a fix for this I may be forced to put my data in the document twice, so that I can have an actual field with the correct name instead of using index\_name.
> 
> Discussion on the forum:
> https://groups.google.com/forum/#!topic/elasticsearch/6-BWdQTPTH0
> 
> Reproduced in 1.4 via this gist:
> https://gist.github.com/pmishev/11375297

On Monday, December 15, 2014 9:41:01 AM UTC-8, Dave Reed wrote:

> I see you tried adding index\_name to the inner field as well. Nope, I'm  
> afraid that did not work.
> 
> Anyone have any thoughts here? This definitely seems like a bug 🙂
> 
> >

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/648de326-80eb-402e-91a0-32ccc57ba7ce%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/648de326-80eb-402e-91a0-32ccc57ba7ce%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:43am UTC](https://discuss.elastic.co/t/search-sort-using-a-field-with-an-index-name-results-in-no-mapping-found/21224/5 "2017-07-06T00:43:21Z")

</div>


