Solr FQ : syntax for OR operator - filter

OR condition is not working for me. Filter Query I am using is:
fq=+(field1:true OR field2:[1 TO *])
Individual:
fq=+(field1:true)
fq=+(field2:[1 to *])
This works just fine.
But ORing of these two conditions is not working as expected.
Am I doing something wrong?

Related

Pythons Elasticsearch-DSL filter for exactly one match from list of values

I saw some realted posts but none of them match my exact issue.
Using Python 2.7 with Elasticsearch-dsl (6.3, that is also my Elasticsearch version).
I want to do something like,
s = Search(using=elastic_conn, index='my_index').filter("match", service_name=['exmp_name1', 'exmp_name2'])
This syntax doesn't work though.
I wish to get back all documents with service_name == 'exmp_name1' OR service_name == 'exmp_name2'
I prefer to use the filter context rather then query context as from my understanding it's faster and scoring really isn't important to me, just an absolute match (or mismatch).
How can I achieve this behavior?
Thanks
Ok. All I needed is to filter by terms rather then match.
The terms syntax supports several values.
Working code:
s = Search(using=elastic_conn, index='audit').filter("terms", service_name=['exmp_name1', 'exmp_name2'])

Google Cloud, compute.instances.aggregatedList with filter fails

The google cloud API for compute.instances.aggregatedList includes filter argument.
https://cloud.google.com/compute/docs/reference/rest/beta/instances/aggregatedList
I use (status eq "RUNNING") as a filter to view all my running instances.
I would like to have a more elaborate criteria, such as one that uses labels and or other terms, however even the Google documentation terms (that use OR operator) returns an error, For example - even Google documentation example:
(cpuPlatform = "Intel Skylake") OR (cpuPlatform = "Intel Broadwell")
fails with error 400:
"message": "Invalid value for field 'filter': ' (cpuPlatform = \"Intel
Skylake\") OR (cpuPlatform = \"Intel Broadwell\")'. Invalid list
filter expression."
it looks as if the '=' signs are not accepted, and AND/OR operators are not accepted.
What is the correct format for this API.
I had the same issue when I used "=" instead of "eq" in google-api-python-client. I required to use labels to filter the aggregated instances list. At first I used
filter="labels.projectid=test-project"
which returned 400 error in aggregated list but was successful if it was queried for instances of specific zone.
I achieved the list successfully when I used filter as
filter="labels.projectid eq \"test-project\""
or
filter = "labels.projectid eq test-project"
I even tested it using REST-Client provided by google and it worked.
Reference: https://issuetracker.google.com/80238913
Even 3 years later Google haven't fixed the bug: OR and AND operators are not supported even it is advertised:
https://cloud.google.com/compute/docs/reference/rest/v1/instances/aggregatedList
Google API is famous for inconsistency and false promises. Just relax and do 2 queries to emulate OR.
For AND operator just omit AND and quote comparison expressions into parentheses:
(name eq 'stage-.*') (labels.env ne "SKIP")
Note I use eq / ne with regex instead of operators =, !=, :.
I ran into a similar error message calling a GCP API. I finally got it to work by making the filter look like this:
fmt.Sprintf("selfLink = \"%s\"", networkLink)
Compute instances list api filter param should work with
(labels.<label_name_1>=<label_value_1>) OR (labels.<label_name_2>=<label_value_2>)
I have found that this string works as a filter within Python:
test_filter = '((labels.test="test-value") AND (labels.test-second="test-second-value")) OR ((labels.test="test-other-value"))'
This filter worked for me:
name eq my-service-v.*
Will return groups like my-service-v112 etc' (even though the name field is nested inside).

Elasticsearch lucene query

I am searching on an element called package, which has the field pkg_scope.
When I add the following string to my query I get 200 results:
AND ( pkg_scope:'Scope Undefined')
When I add the following string instead, I get one result:
AND ( NOT pkg_scope:'Top File')
The one result has a scope 'Scope Undefined'. I think it is reasonable to expect that the second query results would contain the results of the first one. Am I missing something ?
This is the complete query:
query: *:* AND rectype:'Package' AND isPublic:"Yes" AND ( NOT pkg_scope:'Top File' )
I am using ES 1.7.1
The problem was the quotes around the string. For more than one words, double quotes need to be used.
So NOT pkg_scope:'Top File' need to be changed to NOT pkg_scope:"Top File"

Odd behavior with AND condition in elasticsearch

When I run the query (tags:("a")) in elasticsearch, I get 0 results. My query URL looks like:
http://127.0.0.1:9200/haystack/_search?q=(tags%3A(%22a%22))
That is to be expected, since no objects have a tag set to "a".
Now when I change the condition, and add an AND, (org:("1") AND tags:("a")), I get 3 results back! The query URL looks like:
http://127.0.0.1:9200/haystack/_search?q=(org%3A(%221%22)%20AND%20tags%3A(%22a%22))
Getting more results back does not make any sense to me. I would expect that kind of behavior with the OR operator, but AND? What is going on?
Edit: This is caused by the snowball analyzer. See here

XPATH - how to use multiple operators on one query

I am scraping a web URL that looks like this:
www.example.com/pages/popup/popup_report_review.aspx?bikeReviewID=6582049&PageTypeID=9&width=900&height=500
I only want the ID number from it. I tried to run this query first to start the parsing after the "=" and it works perfectly:
normalize-space(substring-after(//a[#id='webpage_url']/#href, '='))
So now I have: 6582049&PageTypeID=9&width=900&height=500
I now want to run another query to just leave me with the ID number so I think this is the one:
substring(//a[#id='webpage_url']/#href,1,7)
This leaves me with only 7 characters. They both work perfectly independently, but I cannot get them to run together. I tried using 'and' but that returns me a number 1.. This is what I did:
normalize-space(substring-after(//a[#id='webpage_url']/#href, '=')) and substring(//a[#id='webpage_url']/#href,1,7)
Does anyone know how I can combine both queries or is there a better way to get this ID? Thanks in advance doe any pointers.
I should use this query:
substring-before(substring-after(//a[#id='webpage_url']/#href, '='), '&')

Resources