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

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'
-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'
-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'
-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'
-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.
For more options, visit https://groups.google.com/groups/opt_out.

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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 16 août 2013 à 00:20, anurag naidu 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' -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' -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' -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' -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.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.

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'
-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'
-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'
-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'
-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.
For more options, visit https://groups.google.com/groups/opt_out.