How should I sort by date results?: Solr - sorting

I'm trying to sort results by date. The server is using Solr technology. Earlier, I was using:
urldata.sort = 'last_modified desc';
to sort by date results. Now it seems to be not working. It throws error:
I referred to this answer regarding sort by date in Solr: How to sort by date in SOLR?
I tried to change 'last_modified desc' to 'published_date desc' but it seems to be not working. How should I proceed to solve this error?

The error isn't related to sorting, but that you aren't search a specific field for any particular value. Since there is no default field defined or specified in the URL, Solr has no idea what do with your search.
Try setting df in the URL, query a specific field foo:value or use qf (with (e)dismax) to specify which field Solr should sort.
Ordering, as long as the field is specified as a date field, should work automagically.

Related

Elasticsearch 7 - prevent fields from being searchable

I know I can prevent fields from being indexed by setting the enabled mapping to false. This does work as expected but I am concerned that some of these fields will be needed in the future.
In my use case, I am searching for a product SKU of t-shirt-small-red and while ES7 does return the correct results, it also returns everything else as I am indexing the created_at and updated_at fields with dates 2020-02-08 00:00:00.
At least for now, I have no use for searching these within my app so I would like a way to exclude these from any search while keeping them indexed for future use. I am guessing I may want to perform filtering or aggregation on these in the future.
I know I can limit the search to just a single field but that does not work for this either. I need the search to work across every field apart from these 2 date fields.
As in one of the comments, you can exclude them from the fields part of the query. I was not using fields before so it actually means specifying all the fields explicitly.
Additionally, I found that specifying the field type as date also ensures they did not show up as false positives in the search.

how to find the date range in uri request search in elasticsearch

I have a search in which i need to find the delta of data
http://localhost:9200/index/index_type/_search?q=sampledate[21-02-2015 TO 22-02-2015]
but this search is giving me error
could anybody help?
You can use below query:
GET /index_name/index_type/_search?q=dateCreated:[2016-01-06+TO+2016-01-07]
This will work only if dateCreated is a date field. Won't work with String
We had similar weird issue with this date field in Elastic Search 7.6.1.
We found working solution by removing colon(:) after date fields and surrounding entire date query part with brackets.
i.e.
GET /index_name/index_type/_search?q=dateCreated:[2016-01-06+TO+2016-01-07]
Above query changed to
GET /index_name/index_type/_search?q=(dateCreated[2016-01-06+TO+2016-01-07]) This should work

How to add a numeric filter on kibana dashboard?

I have a field that contains numbers. I want a filter that shows all logs that are less than a constant value.
When I try to add a new query filter, all I can see is a query string option.
If you are talking about the query field a syntax like this works:
field:<10
Will find just records with a field value less than 10. Found this by experimentation one day -- don't know if it's documented anywhere.

Conditional sorting in Solr 3.6

We're running Solr 3.6 and are trying to apply a conditional sort on the result set. To clarify, the data is a set of bids, and we want to add the option to sort by the current user's bid, so it can't function as a regular sort (as the bid will be different for each user that runs the query).
The documents in the result set include a "CurrentUserId" and "CurrentBid" field, so I think we need something like the following to sort:
sort=((CurrentUserId = 12345) ? CurrentBid : 0) desc
This is just pseudocode, but the idea is that if the currentUserId in Solr matches the user Id (12345 in this example), then sort by CurrentBid, otherwise, just use 0.
It seems like doing a sort by query might be the way to go with achieving this (or at least form part of the solution), using something like the following query:
http://localhost:8080/solr/select/?q=:&sort=query(CurrentUserId:10330 AND CurrentBid:[1 TO *])+desc
This doesn't seem to be working for me though, and results in the following error:
sort param could not be parsed as a query, and is not a field that exists in the index: ...
The Solr documentation indicates that the query function can be used as a sort parameter from Solr 1.4 onwards, so this seems like it should work.
Any advice on how to go about achieving this would be greatly appreciated.
According to the Solr Documentation link you provided,
Any type of subquery is supported through either parameter dereferencing $otherparam or direct specification of the query string in the LocalParams via "v".
So based on the examples and your query, I think one or both of the following should work:
http://localhost:8080/solr/select/?q=:&sort=query($qq)+desc&qq=(CurrentUserId:10330 AND CurrentBid:[1 TO *])
http://localhost:8080/solr/select/?q=:&sort=query({v='CurrentUserId:10330 AND CurrentBid:[1 TO *]'})+desc

How to sort Search Results based on a Field Value in Lucene-3.0.2?

I have googled a lot and also searched in stackoverflow.com about how to sort search results based on a Field Value in Lucene 3.0.2, but not found any useful data. I'm getting the search results from the index, based on the user query but not able to sort the results based on field like id or date.
I have pasted my code here for searching lucene index- http://pastie.org/1033974.
Please help me to solve this problem. If you provide me some example code or links where i can find that will be better.
Thanks
The IndexSearcher class has a couple of search methods that takes a Sort Object that you have to use. A Sort object is basically a wrapper around one or more SortField objects which hold details on what field to sort on and how.
Note that a field must be indexed to be used for sorting.

Resources