# Org.apache.lucene.queryParser.ParseException: Cannot parse 'title: AND BREAKFAST': Encountered " \<AND\> "AND ""

**URL:** <https://discuss.elastic.co/t/org-apache-lucene-queryparser-parseexception-cannot-parse-title-and-breakfast-encountered-and-and/13234>\
**Category:** Elasticsearch\
**Created:** [August 15, 2013, 10:20pm UTC](https://discuss.elastic.co/t/org-apache-lucene-queryparser-parseexception-cannot-parse-title-and-breakfast-encountered-and-and/13234 "2013-08-15T22:20:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anurag\_naidu](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@anurag\_naidu](https://discuss.elastic.co/u/anurag_naidu)\
**Post date:** [August 15, 2013, 10:20pm UTC](https://discuss.elastic.co/t/org-apache-lucene-queryparser-parseexception-cannot-parse-title-and-breakfast-encountered-and-and/13234/1 "2013-08-15T22:20:10Z")

</div>

Hi,

We have a ES setup that indexes on the table(Restaurant) on various fields  
like title, address, city, state, city etc. Also we define a restaurant  
title analyzer with a custom 'stop and 'synonym' filters that defines a  
bunch of stopwords and synonyms. The stopwords is an array that looks  
like STOPWORDS =  
["an","and","at","el","for","il","in","la","le","menu","of","on","restaurant","restaurants","the"]  
that we want filtered during the search.

I am now seeing that certain search queries are failing with a parsing  
failure like below, and in most cases I see that the error happened when  
the title string either starts or ends with a stopword. Not sure if that  
is in any way impacting the error but I can't seem to tell whats wrong with  
the search term to trigger a parse error, other than these tiltles start or  
ends with words like NOT, AND and the likes of a stopword.

Any help would be appreciated. Here are a few CURLs and an error output  
from ES:

curl -X GET  
'[http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)'  
-d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: \*ANDBREAKFAST  
\*","boost":50}},{"query\_string":{"query":"address: 808 PARK  
AVE","boost":50}},{"query\_string":{"query":"phone:  
5016244267","boost":25}}]}},"filter":{"term":{"city\_id":165}},"size":5,"from":0}'

nested: QueryParsingException[[production\_restaurants] Failed to parse  
query [title: AND BREAKFAST]]; nested: ParseException[Cannot parse 'title:  
AND BREAKFAST': Encountered " "AND "" at line 1, column 7.\nWas  
expecting one of:\n ...\n "(" ...\n "_" ...\n  
 ...\n ...\n ...\n ...\n  
"[" ...\n "{" ...\n ...\n]; nested:  
ParseException[Encountered " "AND "" at line 1, column 7.\nWas  
expecting one of:\n ...\n "(" ...\n "_" ...\n  
 ...\n ...\n ...\n ...\n  
"[" ...\n "{" ...\n ...\n]; }

curl -X GET  
'[http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)'  
-d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: _NOT JUST  
PIZZA_","boost":50}},{"query\_string":{"query":"address: 2860 CERRILLOS  
RD","boost":50}},{"query\_string":{"query":"phone:  
5054700955","boost":25}}]}},"filter":{"term":{"city\_id":279}},"size":5,"from":0}'

curl -X GET  
'[http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)'  
-d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: _NOT YOUR  
AVERAGE JOES_","boost":50}},{"query\_string":{"query":"address: 1125 FALL  
RIVER AVE","boost":50}},{"query\_string":{"query":"phone:  
5083435637","boost":25}}]}},"filter":{"term":{"city\_id":41}},"size":5,"from":0}'

curl -X GET  
'[http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)'  
-d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: _RIVALS  
SPORTS BAR GRILL AND_","boost":50}},{"query\_string":{"query":"address: 2650  
NE DIVISION ST","boost":50}},{"query\_string":{"query":"phone:  
5415507771","boost":25}}]}},"filter":{"term":{"city\_id":89}},"size":5,"from":0}'

thanks  
-anurag

--  
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:** ![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:** [August 16, 2013, 5:53am UTC](https://discuss.elastic.co/t/org-apache-lucene-queryparser-parseexception-cannot-parse-title-and-breakfast-encountered-and-and/13234/2 "2013-08-16T05:53:52Z")

</div>

Query string uses Lucene query language.

When using AND (uppercase), Lucene expect to have two operands.

"title: AND BREAKFAST" is not correct.  
If you know on which field you are running your queries, you should use matchQuery instead.

HTH

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 16 août 2013 à 00:20, anurag naidu [anuragnaidu@gmail.com](mailto:anuragnaidu@gmail.com) a écrit :

Hi,

We have a ES setup that indexes on the table(Restaurant) on various fields like title, address, city, state, city etc. Also we define a restaurant title analyzer with a custom 'stop and 'synonym' filters that defines a bunch of stopwords and synonyms. The stopwords is an array that looks like STOPWORDS = ["an","and","at","el","for","il","in","la","le","menu","of","on","restaurant","restaurants","the"] that we want filtered during the search.

I am now seeing that certain search queries are failing with a parsing failure like below, and in most cases I see that the error happened when the title string either starts or ends with a stopword. Not sure if that is in any way impacting the error but I can't seem to tell whats wrong with the search term to trigger a parse error, other than these tiltles start or ends with words like NOT, AND and the likes of a stopword.

Any help would be appreciated. Here are a few CURLs and an error output from ES:

curl -X GET '[http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)' -d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: AND BREAKFAST","boost":50}},{"query\_string":{"query":"address: 808 PARK AVE","boost":50}},{"query\_string":{"query":"phone: 5016244267","boost":25}}]}},"filter":{"term":{"city\_id":165}},"size":5,"from":0}'

nested: QueryParsingException[[production\_restaurants] Failed to parse query [title: AND BREAKFAST]]; nested: ParseException[Cannot parse 'title: AND BREAKFAST': Encountered " "AND "" at line 1, column 7.\nWas expecting one of:\n ...\n "(" ...\n "_" ...\n ...\n ...\n ...\n ...\n "[" ...\n "{" ...\n ...\n]; nested: ParseException[Encountered " "AND "" at line 1, column 7.\nWas expecting one of:\n ...\n "(" ...\n "_" ...\n ...\n ...\n ...\n ...\n "[" ...\n "{" ...\n ...\n]; }

curl -X GET '[http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)' -d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: NOT JUST PIZZA","boost":50}},{"query\_string":{"query":"address: 2860 CERRILLOS RD","boost":50}},{"query\_string":{"query":"phone: 5054700955","boost":25}}]}},"filter":{"term":{"city\_id":279}},"size":5,"from":0}'

curl -X GET '[http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)' -d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: NOT YOUR AVERAGE JOES","boost":50}},{"query\_string":{"query":"address: 1125 FALL RIVER AVE","boost":50}},{"query\_string":{"query":"phone: 5083435637","boost":25}}]}},"filter":{"term":{"city\_id":41}},"size":5,"from":0}'

curl -X GET '[http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)' -d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: RIVALS SPORTS BAR GRILL AND","boost":50}},{"query\_string":{"query":"address: 2650 NE DIVISION ST","boost":50}},{"query\_string":{"query":"phone: 5415507771","boost":25}}]}},"filter":{"term":{"city\_id":89}},"size":5,"from":0}'

## thanks -anurag

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).

--  
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:** ![anurag\_naidu](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@anurag\_naidu](https://discuss.elastic.co/u/anurag_naidu)\
**Post date:** [August 16, 2013, 5:36pm UTC](https://discuss.elastic.co/t/org-apache-lucene-queryparser-parseexception-cannot-parse-title-and-breakfast-encountered-and-and/13234/3 "2013-08-16T17:36:15Z")

</div>

Thanks David, that is quite insightful, makes sense now.

I am been using searchQueries as you can tell, so i'm wondering if I should  
special case the presence of such hanging operator words to use matchQuery  
instead and if that would work? Here is the set of queries I construct (in  
ruby) and I'm not sure if matchQuery can play along the same lines and  
respond to the boost levels relative to the others.

# Create queries for title, address and phone if applicable

```
if title
  t = fulltext_escape(Reports.fulltext_normalize_query(title))
  title_query = lambda do |boolean|
    boolean.should {string "title: #{t}", {:boost => 50} }
  end
end

if address
  s = fulltext_escape(Reports.fulltext_normalize_query(address))
  address_query = lambda do |boolean|
    boolean.should {string "address: #{s}", {:boost => 50} }
  end
end

if phone
  phone_query = lambda do |boolean|
    boolean.should {string "phone: #{phone}", {:boost => 25} }
  end
end

search.query do
  boolean &title_query
  boolean &address_query
  boolean &phone_query
end

```

Appreciate your help  
-anurag

On Thursday, August 15, 2013 3:20:10 PM UTC-7, anurag naidu wrote:

> Hi,
> 
> We have a ES setup that indexes on the table(Restaurant) on various fields  
> like title, address, city, state, city etc. Also we define a restaurant  
> title analyzer with a custom 'stop and 'synonym' filters that defines a  
> bunch of stopwords and synonyms. The stopwords is an array that looks  
> like STOPWORDS =  
> ["an","and","at","el","for","il","in","la","le","menu","of","on","restaurant","restaurants","the"]  
> that we want filtered during the search.
> 
> I am now seeing that certain search queries are failing with a parsing  
> failure like below, and in most cases I see that the error happened when  
> the title string either starts or ends with a stopword. Not sure if that  
> is in any way impacting the error but I can't seem to tell whats wrong with  
> the search term to trigger a parse error, other than these tiltles start or  
> ends with words like NOT, AND and the likes of a stopword.
> 
> Any help would be appreciated. Here are a few CURLs and an error output  
> from ES:
> 
> curl -X GET '  
> [http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)'  
> -d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: \*ANDBREAKFAST  
> \*","boost":50}},{"query\_string":{"query":"address: 808 PARK  
> AVE","boost":50}},{"query\_string":{"query":"phone:  
> 5016244267","boost":25}}]}},"filter":{"term":{"city\_id":165}},"size":5,"from":0}'
> 
> nested: QueryParsingException[[production\_restaurants] Failed to parse  
> query [title: AND BREAKFAST]]; nested: ParseException[Cannot parse 'title:  
> AND BREAKFAST': Encountered " "AND "" at line 1, column 7.\nWas  
> expecting one of:\n ...\n "(" ...\n "_" ...\n  
> ...\n ...\n ...\n ...\n  
> "[" ...\n "{" ...\n ...\n]; nested:  
> ParseException[Encountered " "AND "" at line 1, column 7.\nWas  
> expecting one of:\n ...\n "(" ...\n "_" ...\n  
> ...\n ...\n ...\n ...\n  
> "[" ...\n "{" ...\n ...\n]; }
> 
> curl -X GET '  
> [http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)'  
> -d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: \*NOTJUST PIZZA  
> \*","boost":50}},{"query\_string":{"query":"address: 2860 CERRILLOS  
> RD","boost":50}},{"query\_string":{"query":"phone:  
> 5054700955","boost":25}}]}},"filter":{"term":{"city\_id":279}},"size":5,"from":0}'
> 
> curl -X GET '  
> [http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)'  
> -d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: \*NOTYOUR AVERAGE JOES  
> \*","boost":50}},{"query\_string":{"query":"address: 1125 FALL RIVER  
> AVE","boost":50}},{"query\_string":{"query":"phone:  
> 5083435637","boost":25}}]}},"filter":{"term":{"city\_id":41}},"size":5,"from":0}'
> 
> curl -X GET '  
> [http://172.16.21.21:9200/production\_restaurants/\_search?from=0&size=5&pretty](http://172.16.21.21:9200/production_restaurants/_search?from=0&size=5&pretty)'  
> -d '{"query":{"bool":{"should":[{"query\_string":{"query":"title: _RIVALS  
> SPORTS BAR GRILL AND_","boost":50}},{"query\_string":{"query":"address:  
> 2650 NE DIVISION ST","boost":50}},{"query\_string":{"query":"phone:  
> 5415507771","boost":25}}]}},"filter":{"term":{"city\_id":89}},"size":5,"from":0}'
> 
> thanks  
> -anurag

--  
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:20am UTC](https://discuss.elastic.co/t/org-apache-lucene-queryparser-parseexception-cannot-parse-title-and-breakfast-encountered-and-and/13234/4 "2017-07-06T02:20:51Z")

</div>


