Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lucene Query Syntax of field with a space

Tags:

lucene

I am trying to perform two Lucene queries. The first one works. The second does not. My first query looks like this:

level:"dangerous"

My second query looks like this:

IP address:"11.22.333.444"

I'm not getting a query error. However, I know there are documents with the matching IP address. For that reason, I suspect the space between "IP" and "address" is causing the problem. However, I'm not an expert in Lucene. So, I'm not sure if I'm correct in that.

When I look at my result set using PostMan, I can see a document with a field that looks like this:

"IP address": "11.22.333.444"

Can someone please tell me if my query is correct? Or, if I'm missing something?

Thank you!

like image 216
user3469584 Avatar asked Apr 24 '14 00:04

user3469584


1 Answers

Yes, that space is the problem.

The space in a field name is allowable, but conflicts with query parser syntax. You are essentially running two subqueries combined as SHOULD clauses (ie, an OR):

  • IP
  • address:"11.22.333.444"

You can escape the space using a single slash before the space, like:

IP\ address:"11.22.333.444"
like image 191
femtoRgon Avatar answered Nov 09 '22 23:11

femtoRgon