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).
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).
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:
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:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.