# Searching for a reserved word (OR)

**URL:** <https://discuss.elastic.co/t/searching-for-a-reserved-word-or/3767>\
**Category:** Elasticsearch\
**Created:** [January 12, 2011, 3:30am UTC](https://discuss.elastic.co/t/searching-for-a-reserved-word-or/3767 "2011-01-12T03:30:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![searchersteve](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/searchersteve/32/3008_2.png) [@searchersteve](https://discuss.elastic.co/u/searchersteve)\
**Post date:** [January 12, 2011, 3:30am UTC](https://discuss.elastic.co/t/searching-for-a-reserved-word-or/3767/1 "2011-01-12T03:30:21Z")

</div>

I am trying to run a filter on a field that contains abbreviations for US states. My index contains documents where state=WA and where state=OR. The search works correctly on state=WA, but if I run the identical search for state=OR, I get no hits. No errors -- just no hits.

Is this because "or" is a reserved word and, if so, then how do I work around this issue?

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 12, 2011, 10:12am UTC](https://discuss.elastic.co/t/searching-for-a-reserved-word-or/3767/2 "2011-01-12T10:12:32Z")

</div>

On Tue, 2011-01-11 at 19:30 -0800, searchersteve wrote:

> I am trying to run a filter on a field that contains abbreviations for US  
> states. My index contains documents where state=WA and where state=OR. The  
> search works correctly on state=WA, but if I run the identical search for  
> state=OR, I get no hits. No errors -- just no hits.
> 
> Is this because "or" is a reserved word and, if so, then how do I work  
> around this issue?

Correct. OR is a boolean operator in the Lucene query syntax.  
[http://lucene.apache.org/java/3\_0\_0/queryparsersyntax.html](http://lucene.apache.org/java/3_0_0/queryparsersyntax.html)

Given that state definitions are well defined entities, you probably  
want to store them as not\_analyzed  
[http://www.elasticsearch.com/docs/elasticsearch/mapping/core\_types/#String](http://www.elasticsearch.com/docs/elasticsearch/mapping/core_types/#String)

Then, instead of including the state abbreviation in the query term  
search, you probably want to filter your results with a term filter  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/query\_dsl/term\_filter](http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/term_filter)  
eg :

curl -XGET '[http://127.0.0.1:9200/\_all/\_search](http://127.0.0.1:9200/_all/_search)' -d '  
{  
"query" : {  
"filtered" : {  
"query" : {  
"field" : {  
"\_all" : "keywords to find"  
}  
},  
"filter" : {  
"term" : {  
"state" : "OR"  
}  
}  
}  
}  
}  
'

Note: terms are not analyzed at all, so if you index the state as 'OR'  
then you must filter for it as 'OR', not 'Or' or 'or'

clint

---

<div class="post-metadata">

**Author:** ![searchersteve](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/searchersteve/32/3008_2.png) [@searchersteve](https://discuss.elastic.co/u/searchersteve)\
**Post date:** [January 13, 2011, 9:47pm UTC](https://discuss.elastic.co/t/searching-for-a-reserved-word-or/3767/3 "2011-01-13T21:47:03Z")

</div>

On Tue, 2011-01-11 at 19:30 -0800, searchersteve wrote: \> I am trying to run a filter on a field that contains abbreviations for US \> states. My index contains documents where state=WA and where state=OR. The \> search works correctly on state=WA, but if I run the identical search for \> state=OR, I get no hits. No errors -- just no hits. \> \> Is this because "or" is a reserved word and, if so, then how do I work \> around this issue?

Correct. OR is a boolean operator in the Lucene query syntax.  
[http://lucene.apache.org/java/3\_0\_0/queryparsersyntax.html](http://lucene.apache.org/java/3_0_0/queryparsersyntax.html)

Given that state definitions are well defined entities, you probably  
want to store them as not\_analyzed  
[http://www.elasticsearch.com/docs/elasticsearch/mapping/core\_types/#String](http://www.elasticsearch.com/docs/elasticsearch/mapping/core_types/#String)

Then, instead of including the state abbreviation in the query term  
search, you probably want to filter your results with a term filter  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/query\_dsl/term\_filter](http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/term_filter)  
eg :

curl -XGET '[http://127.0.0.1:9200/\_all/\_search](http://127.0.0.1:9200/_all/_search)' -d '  
{  
"query" : {  
"filtered" : {  
"query" : {  
"field" : {  
"\_all" : "keywords to find"  
}  
},  
"filter" : {  
"term" : {  
"state" : "OR"  
}  
}  
}  
}  
}  
'

Note: terms are not analyzed at all, so if you index the state as 'OR'  
then you must filter for it as 'OR', not 'Or' or 'or'

clint

Thanks!!! I was, in fact, searching for state with a filter, but I did not know about the not\_analyzed solution. I am realizing that I have a number of fields that are like this (discrete and predictable values), and I suspect that I could improve indexing speed quite a bit if I selected not\_analyzed.

I'll try out your suggestion and let you know if problems arise. Thanks again for the schooling.

Steve

---

<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, 4:13am UTC](https://discuss.elastic.co/t/searching-for-a-reserved-word-or/3767/4 "2017-07-06T04:13:57Z")

</div>


