How to use multiple indexes to filter and group? - rethinkdb

In RethinkDB, is it possible to filter and group in a single query using indexes for efficiency in both operations? For instance:
r
.db('db')
.table('table')
.getAll('123', {index: 'serverId'})
.group({index: 'userId'})
.ungroup()
When I try this, it throws an error. I read in a few places what seems to suggest that RethinkDB is not capable of using multiple indexes in this way. Is this true or am I doing something wrong?

You can use secondary index only one time in a query.

Related

append multiple queries into single and pass it in go-elasticsearch newboolquery for search

I want to perform a advance elasticsearch in my chat application which is written in go. So, I have used go-elasticsearch to perform general search using elastic search in my chat application.
for advance elasticsearch I need three query builder/raw query builder that contains filter queries, not filter, excludeterms. like in filterqueries I have append multiple newtermqueries based on condition. After making these three queries I want to pass it into newboolquery function to perform must, should, must_not like, elasticsearch.addmust(filter queries) , elasticsearch.should(not filter) etc.
the problem is I have tried both library olivere and go-elasticsearch for it but didn't succeed. I think I am doing something wrong. can anyone help me?

Filter result in memory to search in elasticsearch from multiple indexes

I have 2 indexes and they both have one common field (basically relationship).
Now as elastic search is not giving filters from multiple indexes, should we store them in memory in variable and filter them in node.js (which basically means that my application itself is working as a database server now).
We previously were using MongoDB which is also a NoSQL DB but we were able to manage it through aggregate queries but seems the elastic search is not providing that.
So even if we use both databases combined, we have to store results of them somewhere to further filter data from them as we are giving users advanced search functionality where they are able to filter data from multiple collections.
So should we store results in memory to filter data further? We are currently giving advanced search in 100 million records to customers but that was not having the advanced text search that elastic search provides, now we are planning to provide elastic search text search to customers.
What do you suggest should we use the approach here to make MongoDB and elastic search together? We are using node.js to serve data.
Or which option to choose from
Denormalizing: Flatten your data
Application-side joins: Run multiple queries on normalized data
Nested objects: Store arrays of objects
Parent-child relationships: Store multiple documents through joins
https://blog.mimacom.com/parent-child-elasticsearch/
https://spoon-elastic.com/all-elastic-search-post/simple-elastic-usage/denormalize-index-elasticsearch/
Storing things client side in memory is not the solution.
First of all the simplest way to solve this problem is to simply make one combined index. Its very trivial to do this. Just insert all the documents from index 2 into index 1. Prefix all fields coming from index-2 by some prefix like "idx2". That way you won't overwrite any similar fields. You can use an ingestion pipeline to do this, or just do it client side. You only will ever do this once.
After that you can perform aggregations on the single index, since you have all the data in one-index.
If you are using somehting other than ES as your primary data-store you need to reconfigure the indexing operation to redirect everything that was earlier going into index-2 to go into index-1 as well(with the prefixed terms).
100 million records is trivial for something like ELasticsearch. Doing anykind of "joins" client side is NOT RECOMMENDED, as this will obviate the entire value of using ES.
If you need any further help on executing this, feel free to contact me. I have 11 years exp in ES. And I have seen people struggle with "joins" for 99% of the time. :)
The first thing to do when coming from MySQL/PostGres or even Mongodb is to restructure the indices to suit the needs of data-querying. Never try to work with multiple indices, ES is not built for that.
HTH.

How can I get information from 2 different ElasticSearch indexes?

So, I have 2 indexes in my Elasticsearch server.
I need to gather the results from the first index, and for each result I need to gather info from the second index.
How to do that? Tried the foreach processor, but no luck so far.
Tky
I need to gather the results from the first index, and for each result I need to gather info from the second index.
Unless you create parent/child relationships, that's not possible in ElasticSearch.
However, note:
In Elasticsearch the key to good performance is to de-normalize your data into documents. Each join field, has_child or has_parent query adds a significant tax to your query performance.
Handle reading from multiple indexes within your application or rethink your index mapping.
The foreach processor is for ingest pipelines, meaning, stuff that gets done at indexing time. So it won't help you when you are trying to gather the results.
In general, it's not going to be possible to query another index (which might live on another shard) from within a query.
In some cases, you can use a join field. There are performance implications, it's only recommended in specific cases.
If you are not in the join field use case, and you can restructure your data to use nested objects, it will be more performant than join fields.
Otherwise, you'll be better off running multiple queries in the application code (maybe you can fetch all the "secondary" results using just one query, so you'd have 2 queries in total?)

Need elasticsearch query to fetch data based on some condition which has around 10K values check for particular column

Need to write a cassandra or elasticsearch query which is equivalent to SQL "in" condition query.
In the "in" condition there are around 10K values to be matched.
Please suggest some good approach for this.
I tried with elasticsearh filters for some data. But I think it is not a good solution

Solr combined (AND) query performance

Need to perform the following query in solr:
field_a:"A" AND field_b:/.*sear.* ph.ase.*/
single field_a:"A" query is super fast;
single field_b:/.*sear.* ph.ase.*/ query is slowish;
combined with AND query is slow too;
Setting either one of those query parts as filter doesn't work, the performance is still bad!
Is there a way to instruct solr to perform a search for the second query on the results of the first (to improve performance)?
Thanks!
Can you make the first query a filter query instead of a regular query. That tends to speed up the results in my experience.

Resources