How to filter text array with items in list case insensitively in Supabase? - supabase

I have a text array (text[]) in Supabase. Let's say it's like this:
["Car", "Red", "New"]
I would like to get this row by filtering with list of words. So when I query new or car or red or any combination of these words, I should get the row with the array above. In other words, querying text[] with list of items.
So this query with ["new", "red"] should return the column above.
Any idea how to do that?

Related

ElasticSearch - backward pagination with search_after when sorting value is null

I have an application which has a dashboard, basically a table with hundreds of thousands of records.
This table has up to 50 different columns. These columns have different types in mapping: keyword, text, boolean, integer.
As records in the table might have the same values, I use sorting as an array of 2 attributes:
First attribute is what client wants to sort by. It can be a simple
sorting object or some sort query with nested filter.
Second
attribute is basically a default sorting by id, needed for sorting
the documents which have identical values for the column customer
wants to sort by.
I checked multiple topics/issues on github and here
on elastic forum to understand how to implement search_after
mechanism for back sorting but it's not working for all the cases I
need.
Please have a look at the image:
Imagine there is a limit = 3, the customer right now is on the 3d page of a table and all the data is sorted by name asc, _id asc
The names are: A, B, C, D, E on the image.
The ids are numeric parts of the Doc word.
When customer wants to go back to the previous page, which is a page #2 on my picture, what I do is pass the following to elastic:
sort: [
{
name: 'desc'
},
{
_id: 'desc'
}
],
search_after: [null, Doc7._id]
As as result, I get only one document, which is Doc6: null on my image. It seems to be logical, because I ask elastic to search by desc after null and id 7 and I have only 1 doc corresponding this..it's Doc6 but it's not what I need.
I can't make up the solution to get the data that I need.
Could anyone help, please?

Elasticsearch query based on properties of another document

Is there a way in ES to do a single query that finds documents that are based on values "close" (whose logic I determine) to values in another document?
Example: i have document like this:
{
"myId": 10,
"price": 200
}
Now I want to run a query that finds documents that are within 100 either side of the price of the above document (but I don't know the price of document on the client..all I have is the myId)
In other words, i want to write a client method like this:
GetSimilarDocuments(int myId);
Is that possible to do in a single ES query? Or do I need two round trips? (get the document, then do another query based on the values of the document)

query the first element of a list in ElasticSearch

In my Elasticsearch index I have fields that are lists of strings:
"city" = ["Boston","NY","Chicago"]
I need to write a query that searches only the first element of the list.
I have accomplished this by adding a new field that contains only the first element.
"city_first"="Boston"
I like to avoid creating a new field. Is there a way to write a query that searches only the 1st element of the list in Elasticsearch?

How to turn off ag-grid quick filter for specific column

AG-grid has "quick filter" feature, essentially a free-text search filter that searches through all columns.
The problem is, in some columns, I have date-time values and I don't want to search through data in those columns.
Using "column filter" to filter on each column separately is not an option because this will give me "AND" behavior: only when all columns that I search through contain the data I search for will this column be visible. And I need "OR" behavior: a row that contains the data I search for in any column (except column that has date-time values) should be visible.
So, how can I remove some columns from the set of columns this "quick filter" searches through?
I just needed to set an "empty" function as "getQuickFilterText" function for the column I don't want to search through:
colDef = {
getQuickFilterText: () => ''
}

Sum of total tokens in array

I have a document as below -
{
"array" : [ "Aone" , "Btwo" , "Aone" ]
}
I need to aggregate the sum of number of elements in array using aggregation.
value_count is giving me the unique tokens , but that is not what i am looking for.
First you need to make array a multi field with a new field called numOfTokens . Declare this field as token count.
You can find more about it here -http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#token_count
This will create an addition field called array.numOfTokens per document that will have the number of tokens for that field.
Next you can do a simple sum aggregation on that field using - http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html#search-aggregations-metrics-sum-aggregation

Resources