Must returns more results than Filter - elasticsearch

I checked this question What is the difference between must and filter in Query DSL in elasticsearch? and read answers.
As far as I understood must and filter should return same result. Am I right? But when I change filter query to must, I receive more result? What I am doing wrong?
I compared filter and must query and got different result.

Must query gives you some score that is used to add to the total score of the doc.
Filter query does not add any score. It is just used to decide whether a doc is returned or not in the result set.
By just looking at the screenshot of the query attached, when you change filter query to must query it starts adding some value to the total score of the doc.
Since you are using min_score condition, the must clause makes more docs exceed 0.2 score and hence more docs are returned in the final result set.
Rest things will be more clear when you share the complete query.

Related

How to search result set from a result set in elasticsearch

Im tring to understand the DSL query i needed if i want to make a search from a result set i got. means i have an initial term search, then i want make another query upon the previous result.
lets say i a have 10 documents with a sharing identifier between them, each document has a description field. i want to search first all the documents containing the value 'Hello' in the description and then take their id's, and search the document containing the value 'good by'.
thanks.
No need to execute two queries, you can use filter context that will filter out the results.filter parameter will filter out documents that do not match, and will also not affect the score for matching documents.
Filter context is in effect whenever a query clause is passed to a
filter parameter, such as the filter or must_not parameters in the
bool query, the filter parameter in the constant_score query, or the
filter aggregation.
Refer this to know more about Query and Filter contexts

Boosting score in Elasticsearch based on aggregation result

I need to boost the score of my documents based on a particular value. That value can be obtained from aggregation query.
Currently I am using 2 queries to do it, would like to achieve it in a single query.
1-So basically first query gets me the highest no of occurrence of a particular chapter based on a simple term/match query.
2- Next step is once I get the highest occurring chapter will fire another query which would basically have the same above query with another term query added with a boost factor of 10.
Any input with this regards is welcomed, if we can accomplish this in one query. Thanks in advance.
Ashit

Solr boost query sort by whether result is boosted then by another field

I'm using Solr to run a query on one of our cores. Suppose my documents have two fields: ID, and Name. I also have a separate list of IDs I'm grabbing from a database and passing into the query to boost certain results.
If the document gets returned in the query and the ID is in the list it goes to the top of the results, and if it gets returned in the query and the ID is not in the list then it goes below those that are in the list. The former is from the "boost". My query is something like this -
http://mysolrserver:8983/solr/MyCore/MyQueryHandler?q=Smith&start=0&rows=25&bq=Id%3a(36+OR+76+OR+90+OR+224+OR+391)
I am able to get the boost query working but I need the boosted results to be in alphabetical order by name, then the non boosted results under that also in alphabetical order by name. I need to know what to user for the &sort= parameter.
&sort=score%20desc,Name+asc does not work.
I've looked over a lot of documentation, but I still don't know if this even possible. Any help is appreciated. Thanks!
Solr version is 6.0.1. I am actually using SolrNet to interface with Solr, but I think I can figure out the SolrNet part if I know what the url's &sort= parameter value needs to be.
I figured it out, by doing away with the boost query. I added a sort query using the "exists" function and passing it a sub-query for the ID. The exists returns a boolean value to sort on, then I added the name as a second sort. It works perfect!!
The URL looks like this:
http://mysolrserver:8983/solr/MyCore/MyQueryHandler?q=Smith&start=0&rows=25&sort=exists(query({!v=%27Id:(36+OR+76+OR+90+OR+224+OR+391)%27}))%20DESC,%20Name%20ASC
The closest match to your requirement is the query elevation component[1] .
In your particular case I would first sort my Ids according to my requirements ( sorting them by name for example), then maintain them in the elevate.xml.
At query time you can use the "forceElevation" parameter to force the elevation and then sort the remaining results by name.
[1] https://cwiki.apache.org/confluence/display/solr/The+Query+Elevation+Component

How can I get response(which is searched by score) in Elasticsearch?

I need your help. I want to a search which can be search by common conditions and its score range also used as conditions。Can I do it successfully? if you know ,I hope you can share.
I have a example in the picture:
In the picture,we know the score range is [0,1] ,if I want to get response which scores is [0.2,0.6],How do it! help! SOS! Execute my English!
Elasticsearch provides a min_score field that can be included in a request body search to filter out documents with a _score less than a specified value.
There is no way to filter out documents with a _score greater than a certain value, but: why do you want to do this? Scores in Lucene by definition mean that documents were found matching your search query, and that some results are more relevant than others. I recommend that you read "What is Relevance?" in the Elasticsearch documentation, and "Apache Lucene - Scoring" for a basic understanding of how the scoring formula works.
Also, the Lucene score range isn't always [0,1]: it can be greater than 1.

ElasticSearch / Tire & Keywords. Right way to match "or" for a keyword list?

I've got an Entity model (in Mongoid) that I'm trying to search on its keywords field which is an array. I want to do a query where I pass in an array of potential search terms, and any entity that matches any of the terms will pass.
I don't have this working well yet.
But, why I'm asking this question, is that it's more complex. I also DONT want to return any entities that have been marked as "do not return" which I do via a "ignore_project_ids" parameter.
So, when I query, I get 0 results. I was using Bonsai.io. But, I've moved this to my own EC2 instance to reduce complexity/variables on solving the problem.
So, what am I doing wrong? Here are the relevant bits of code.
https://gist.github.com/3405763
You want a terms query rather than a term query - a term query is only interested in equality, whereas a terms query requires that the field match any of the specified values.
Given that you don't seem to care about the query score (you're sorting by another attribute), you'll get faster queries by using a filtered query and expressing your conditions as filters

Resources