Solr: Excluding certain documents from getting sorted - sorting

I have a Solr query where i am trying to sort the results based on a certain field.
I want to modify it in such a way that only a particular set of documents get sorted and the remaining are simply appended to the end of the sorted list.
Is there a way to achieve this?
Please help.
Regards.

If you want to Sort by a particular field condition which is dynamic, you can boost the field with matching condition higher and sort by score.
for e.g. bq=some_field:some_value^10
This will boost the scores of the documents only matching the criteria.
Also, for all the other documents the score would be unchanged and would follow the boasted documents as is.
EDIT :-
you can boost on multiple fields e.g. bq=string_array_field:some_value^10&bq=ranking^10 would boost the documents matching the value and the having higher ranking to the top.
The rest of the documents would follow.

For each <fieldType> definition in your schema.xml you can set a sortMissingLast="true" option that would give you the desired sorting behavior. For your specific example, I would recommend creating a new field with the sortMissingLast="true" set and use then populate this additional field based on your given criteria and not setting a value for those documents you want to appear at the end when sorted.

Related

Elastic Search and Search Ranking Models

I am new to Elastic Search. I would like to know if the following steps are how typically people use ES to build a search engine.
Use Elastic Search to get a list of qualified documents/results based on a user's input.
Build and use a search ranking model to sort this list.
Use this sorted list as the output of the search engine to the user.
I would probably add a few steps
Think about your information model.
What kinds of documents are you indexing?
What are the important fields and what field types are they?
What fields should be shown in the search result?
All this becomes part of your mapping
Index documents
Are the underlying data changing or can you index it just once?
How are you detecting new docuemtns/deletes/updates?
This will be included in your connetors, that can be set up in multiple ways, for example using the Documents API
A bit of trial and error to sort out your ranking model
Depending on your use case, the default ranking may be enough.
have a look at the Search API to try out different ranking.
Use the search result list to present the results to the end user

ElasticSearch and Searching in Arrays

We have an ES index which has a field which stores its data as an array. In this field, we include the original text, plus text without any punctuation, special characters, etc. The problem is, when searching on the field, the multiple values appears to be skewing the score.
For example, if we search on the term 'up', the document which has the array ['up, up and away', 'up up and away'] is scoring higher with a multi_match (we are using because we may search more than one field) than the document with the array as simply ['up'].
In the end, I guess what I am looking for is a score that emulates calculating a score for each item in the array and returning me the highest. I believe in this case, comparing 'up' to 'Up' and 'Up, Up and Away' will give me a higher score for 'Up'.
With my research, I believe I may need to do custom scoring on this field...? If that is true, am I looking at "score_mode": "max" as what I want?
I think you slightly over-engineered your index. You don't need to create duplicate fields for the same information and remove punctuation, lowercase fields yourself.
I'd recommend you to read what are elasticsearch token filters and how to create multiple analyzers for the same field.
For your exact use case, if you provided a document sample, it would certainly help. But in any case looking at what you are dealing with - index your array of strings with default analyzer and with a custom one that you'll build yourself. Then you can use the same field, but with different analyzers (differently processed text) to control your score.

How to sort (and give weight) by Availability dates in SolR

i'm facing a big problem in my SolR DB.
My objects have a datetime field "Available_From" and a datetime field "Available_To".
We also have a "Ranking" field for the sorting.
I can search correctly with direct queries (eg. give me all the items that are available at the moment) but when i do a regular search i cannot find a way to show the items that result "available NOW" in the first places in the results, usually sorted by "Ranking" field.
How can i do this? Am I forced to write some java classes (the nearest thing i've found is there https://medium.com/#devchaitu18/sorting-based-on-a-custom-function-in-solr-c94ddae99a12) or is there a way to do with standard SolR queries?
Thanks in advance to everyone!
In your case you actually don't want sorting, since that indicates that you want one field to determine the returned sequence of documents.
Instead, use boosting - apply a very large boost to those that are available now, either through bq or boost, then apply a boost based on ranking. You'll have to tweak the weights given to each part based on how you want the search results to be presented.

Weird results using Search After () elastic search

i am having issues with search after api in elastic search.
please see this link where i posted the full description of the problem
https://discuss.elastic.co/t/weird-results-using-search-after-elastic-search/116609?u=ayshwarya_sree
As per the documentation for searchAfter
A field with one unique value per document should be used as the
tiebreaker of the sort specification. Otherwise the sort order for
documents that have the same sort values would be undefined. The
recommended way is to use the field _id which is certain to contain
one unique value for each document.
Since you are only passing gender as sorting criteria, on your next second request it assumes that you are expecting results after Female, which will be results with gender Male.
Try adding _id as sort and searchafter parameter too

Sorting string column in Kibana visualization

I have a status field in my elastic search index which can take values Open,Closed,Clear,Intermediate,Ready for Approval. Right now, I have created a visualization and sorted this field descending based on the Term. What I want to achieve is - I want this to be sorted in this particular order Open,Clear,Intermediate,Ready for Approval,Closed.
How do I achieve this? One option I am thinking is creating a scripted field and prefixing with integer column, but I am not sure if I will be able to filter the visualization later?
If this list of possible values is a static list of known values, there is another way to define your visualization with a little more manual configuration. Just replace your terms aggregation with a filters aggregation and add custom filters for the possible values like so:
Kibana will respect the order of your filters in the visualization. From a performance perspective, this should also be better than using a scripted field...

Resources