3

I got the below error in my project:

org.apache.lucene.queryParser.ParseException: Cannot parse 'AMERICAN EXP PROPTY CASLTY INS AND': Encountered "" at line 1, column 34. Was expecting one of: ... "+" ... "-" ... "(" ... "" ... ... ... ... ... "[" ... "{" ... ... ... "" ...

at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:211)
at org.elasticsearch.index.query.xcontent.QueryStringQueryParser.parse(QueryStringQueryParser.java:196)
... 15 more

Please help on how to resolve...when i add an AND at the end of any string it gives me the above error.

Thanks

1
  • Looks like you missed to escape some character, you would need to share your query Commented Oct 15, 2012 at 6:38

3 Answers 3

3

When you are using QueryString query or specifying your query as a q parameter, elasticsearch is using Lucene to parse your query. As a result, it expects your query to follow Lucene query syntax and returns errors when your query contains syntax errors (dangling AND at the end, in your case). If you want your query string to be interpreted as text and not parsed as a query, consider using Text Query instead.

Sign up to request clarification or add additional context in comments.

2 Comments

i'm using QueryStringQueryBuilder querystring = new QueryStringQueryBuilder(data); // data = AMERICAN EXP PROPTY CASLTY INS AND Can you please explain a bit more through code...as i'm very much new to all these..and greatly require any help regarding these.. thanks.
In java API, it would look like this MatchQueryBuilder matchPhrase = new MatchQueryBuilder("_all", data).type(MatchQueryBuilder.Type.PHRASE)
0

That's funny. Lucene is waiting for a new term as in Lucene you can build queries like : "termA AND termB" or "+termA +termB"

Can you try to lowercase your query and see if it works?

3 Comments

Thank you very much for the reply.. yes i tried to make the it to lower case in case if AND is First or last of the string ...it worked But there is one more problem in other case like if the string has two or more consecutive AND's ...i get the parsing exception error i can remove the duplicate consecutive terms but i dont want to do that ... is there any other way to keep the string unaltered yet no error..?? plz help..Thanks in advance
I don't understand if it's a common use case to have a AND (or more than one AND) at the end of a search query. Is it a reserved word for your use case?
ok..I just made all the occurences of AND's in a string to small case(and), it's working now..Actually i have a program in which i search for the given string using the query..and the input string can be anything...therefore just ensuring that no error occurs in case of more than one consecutive AND's in a string.
0

use correct package name and classpath parser P is small letter

org.apache.lucene.queryparser.classic.ParseException

<dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-queryparser</artifactId>
        <version>4.3.0</version>
    </dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.