Lucene query strings


(mattcollins84) #1

Hi all,

I want to user a fairly complex lucene query string with ElasticSearch:

(((isCustomer:1 AND (tagid:1959) AND (locid:14648) AND (portalid:1 OR portalid:2))^50000) OR ((isCustomer:1 AND NOT tagid:1959 AND (catid:L929) AND (locid:14648) AND (portalid:1 OR portalid:2))^25000) OR ((NOT isCustomer:1 AND (catid:L929 OR companyName:hotel) AND (locid:14648) AND (portalid:1 OR portalid:2))^5000) OR ((NOT isCustomer:1 AND (catid:L929 OR companyName:hotel OR hotel) AND (locid:14648) AND (portalid:1 OR portalid:2)))) AND NOT adultContent:true

But this doesn't seem to work (from my bash shell at least!). The error I get is:

-bash: syntax error near unexpected token `('

Can anyone shed any light on how I could go about this? I have tried URL encoding the query, but to no avail (same error).

Thanks,
Matt


(vineeth mohan) #2

Can you paste the entire command you executed.

Again this is not a ES issue , its strictly something to do with bash/shell
scripting.
I don't think this is the group you need to raise this query.

Thanks
Vineeth

On Wed, Aug 10, 2011 at 7:31 PM, mattcollins84
mattstrikes@googlemail.comwrote:

Hi all,

I want to user a fairly complex lucene query string with ElasticSearch:

(((isCustomer:1 AND (tagid:1959) AND (locid:14648) AND (portalid:1 OR
portalid:2))^50000) OR ((isCustomer:1 AND NOT tagid:1959 AND (catid:L929)
AND (locid:14648) AND (portalid:1 OR portalid:2))^25000) OR ((NOT
isCustomer:1 AND (catid:L929 OR companyName:hotel) AND (locid:14648) AND
(portalid:1 OR portalid:2))^5000) OR ((NOT isCustomer:1 AND (catid:L929 OR
companyName:hotel OR hotel) AND (locid:14648) AND (portalid:1 OR
portalid:2)))) AND NOT adultContent:true

But this doesn't seem to work (from my bash shell at least!). The error I
get is:

-bash: syntax error near unexpected token `('

Can anyone shed any light on how I could go about this? I have tried URL
encoding the query, but to no avail (same error).

Thanks,
Matt

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Lucene-query-strings-tp3242645p3242645.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(Clinton Gormley) #3

Hi Matt

I want to user a fairly complex lucene query string with ElasticSearch:

(((isCustomer:1 AND (tagid:1959) AND (locid:14648) AND (portalid:1 OR
portalid:2))^50000) OR ((isCustomer:1 AND NOT tagid:1959 AND (catid:L929)
AND (locid:14648) AND (portalid:1 OR portalid:2))^25000) OR ((NOT
isCustomer:1 AND (catid:L929 OR companyName:hotel) AND (locid:14648) AND
(portalid:1 OR portalid:2))^5000) OR ((NOT isCustomer:1 AND (catid:L929 OR
companyName:hotel OR hotel) AND (locid:14648) AND (portalid:1 OR
portalid:2)))) AND NOT adultContent:true

Besides the error you're getting in bash, I really recommend that you
don't try to use the lucene query syntax for queries this complex. They
become impossible to read and debug.

Much better to use the query DSL for this.

I've tried to analyze the logic of your query above:

isCustomer tagid catid/companyName/text locid portalid adultContent boost

1 1959 -- 14648 1 or 2 false 50000
1 !1959 -- 14648 1 or 2 false 25000
!1 -- L929/hotel/-- 14648 1 or 2 false 5000
!1 -- L929/hotel/text 14648 1 or 2 false --

First thing to note is that the last line doesn't make sense. It's the
same as the line before, but MORE specific.

Second, locid, portalid and adultContent always have the same value, and
don't affect the scoring.

I've mocked up how you could run this query using the
custom_filters_score query. This may not be exactly right, as I don't
have all the details of your data, but should get you started:

clint


(system) #4