# What are the allowed characters in field names?

**URL:** <https://discuss.elastic.co/t/what-are-the-allowed-characters-in-field-names/5621>\
**Category:** Elasticsearch\
**Created:** [October 18, 2011, 7:39am UTC](https://discuss.elastic.co/t/what-are-the-allowed-characters-in-field-names/5621 "2011-10-18T07:39:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![datadev](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@datadev](https://discuss.elastic.co/u/datadev)\
**Post date:** [October 18, 2011, 7:39am UTC](https://discuss.elastic.co/t/what-are-the-allowed-characters-in-field-names/5621/1 "2011-10-18T07:39:17Z")

</div>

What are the allowed characters in field names? Specifically, are  
hyphens allowed in field names? I currently have a term facet that has  
a 'script' attribute being "term + 'aaa' + \_source.foo-bar" and I am  
getting the following exception: Query Failed [Failed to execute main  
query]]; nested: PropertyAccessException[[Error: could not access:  
[bar; in class: org.elasticsearch.search.lookup.SourceLookup]

Based on this exception, it seems that ES is treating the hyphen as a  
delimiter between 2 fields?

If hyphens are not allowed in field names, is there definitive  
documentation on what characters (ideally in a regex if there are also  
rules about acceptable first characters, etc...) are allowed in field  
names?

Thanks.

---

<div class="post-metadata">

**Author:** ![datadev](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@datadev](https://discuss.elastic.co/u/datadev)\
**Post date:** [October 18, 2011, 7:49am UTC](https://discuss.elastic.co/t/what-are-the-allowed-characters-in-field-names/5621/2 "2011-10-18T07:49:00Z")

</div>

BTW, here is a link regarding field names in solr for reference:  
[https://issues.apache.org/jira/browse/SOLR-2606](https://issues.apache.org/jira/browse/SOLR-2606)

On Oct 18, 3:39 am, datadev [n...@adinfocenter.com](mailto:n...@adinfocenter.com) wrote:

> What are the allowed characters in field names? Specifically, are  
> hyphens allowed in field names? I currently have a term facet that has  
> a 'script' attribute being "term + 'aaa' + \_source.foo-bar" and I am  
> getting the following exception: Query Failed [Failed to execute main  
> query]]; nested: PropertyAccessException[[Error: could not access:  
> [bar; in class: org.elasticsearch.search.lookup.SourceLookup]
> 
> Based on this exception, it seems that ES is treating the hyphen as a  
> delimiter between 2 fields?
> 
> If hyphens are not allowed in field names, is there definitive  
> documentation on what characters (ideally in a regex if there are also  
> rules about acceptable first characters, etc...) are allowed in field  
> names?
> 
> Thanks.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 18, 2011, 5:45pm UTC](https://discuss.elastic.co/t/what-are-the-allowed-characters-in-field-names/5621/3 "2011-10-18T17:45:59Z")

</div>

There isn't really a limit on what can be in a field name. In your case, the  
script is actually a script (by default, mvel). Since \_source is actually  
treated as a Map lookup, you can do \_source['foo-bar'].

On Tue, Oct 18, 2011 at 9:39 AM, datadev [nji@adinfocenter.com](mailto:nji@adinfocenter.com) wrote:

> What are the allowed characters in field names? Specifically, are  
> hyphens allowed in field names? I currently have a term facet that has  
> a 'script' attribute being "term + 'aaa' + \_source.foo-bar" and I am  
> getting the following exception: Query Failed [Failed to execute main  
> query]]; nested: PropertyAccessException[[Error: could not access:  
> [bar; in class: org.elasticsearch.search.lookup.SourceLookup]
> 
> Based on this exception, it seems that ES is treating the hyphen as a  
> delimiter between 2 fields?
> 
> If hyphens are not allowed in field names, is there definitive  
> documentation on what characters (ideally in a regex if there are also  
> rules about acceptable first characters, etc...) are allowed in field  
> names?
> 
> Thanks.

---

<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:51am UTC](https://discuss.elastic.co/t/what-are-the-allowed-characters-in-field-names/5621/4 "2017-07-06T03:51:32Z")

</div>


