mongodb-java-driver how to group multiple fields? - mongodb-java

Does mongodb-java-driver group only support one field? e.g.
group("$customerId", sum("totalQuantity", "$quantity"), avg("averageQuantity", "$quantity"))
if group with multi fields, how to implement? e.g.
"_id":{platform:"$platform",screen_name:"$screen_name"}
I tried below manner, but it does not work
group("{platform:\"$platform\",screen_name:\"$screen_name\"}", sum("totalQuantity", "$quantity")
So how to support multiple group field in mongodb-java-driver?

Related

Is there a way to query two indexes and join the result in Opensearch/ElasticSearch (Just like we do in RDBMS)

My requirement is
I have a deeply nested filter condition
Params from filter condition is located in two elastic search indexes
I need to pass the filter condition as query and get results which are joined by a field
The existing way is to use two indexes comma separated and searching but is supports only or - should condition. Reference : https://discuss.elastic.co/t/query-multiple-indexes-but-apply-queries-to-specific-index/127858
I need a way to support to and - must condition also.
Is there a possibility to do that? Thanks in Advance

How to do group by multiple fields and sort on a different field, in elasticsearch

Lets say I have a query like
Select * from table
Group By field_1, field_2, field_3
Order By filed_7;
How to achieve the same functionality in elasticsearch.
I use Composite Aggregations to do Group by multiple fields. Is it possible to do the sorting part?

Unable to demonstrate common fields on the same column using Kibana?

I am using two different indexes which are named cdr_mobile and cdr_volte that have lots of common fields. So in order to show datas on Kibana I have made an alias using two of them cdr_alias and now I am using cdr_alias in order to retieve data to Kibana.
The problem I have is, I cannot demonstrate common fields on the same column. Instead of that I am having for example, cdr_volte.startOfCharge and startOfCharge (the other thing I dont understand is here, it is using the cdr_mobile as default).
Do you have any idea how I can put the common fields on the same column ?
Thank you
I have made an error on mapping, In order to put same fields on the same column you must have exactly same mapping for the field for both indices.

Elasticsearch indexed database table column structure

I have a question regarding the setup of my elasticsearch database index... I have created a table which I have rivered to index in elasticsearch. The table is built from a script that queries multiple tables to denormalize data making it easier to index by a unique id 1:1 ratio
An example of a set of fields I have is street, city, state, zip, which I can query on, but my question is , should I be keeping those fields individually indexed , or be concatenating them as one big field like address which contains all of the previous fields into one? Or be putting in the extra time to setup parent-child indexes?
The use case example is I have a customer with billing info coming from one direction, I want to query elasticsearch to see if that customer already exists, or at least return the closest result
I know this question is more conceptual than programming, I just can't find any information of best practices.
Concatenation
For the first part of your question: I wouldn't concatenate the different fields into a field containing all information. Having multiple fields gives you the advantage of calculating facets and aggregates on those fields, e.g. how many customers are from a specific city or have a specific zip. You can still use a match or multimatch query to query for information from different fields.
In addition to having the information in separate fields I would use multifields with an analyzed and not_analyzed part (fieldname.raw). This again allows for aggregates, facets and sorting.
http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/mapping-multi-field-type.html
Think of 'New York': if you analyze it will be stored as ['New', 'York'] and you will not be able to see all People from 'New York'. What you'd see are all people from 'New' and 'York'.
_all field
There is a special _all field in elasticsearch which does the concatenation in the background. You don't have to do it yourself. It is possible to enable/disable it.
Parent Child relationship
Concerning the part whether to use nested objects or parent child relationship: I think that using a parent child relationship is more appropriate for your case. Nested objects are stored in a 'flattened' way, i.e. the information from the nested objects in arrays is stored as being part of one object. Consider the following example:
You have an order for a client:
client: 'Samuel Thomson'
orderline: 'Strong Thinkpad'
orderline: 'Light Macbook'
client: 'Jay Rizzi'
orderline: 'Strong Macbook'
Using nested objects if you search for clients who ordered 'Strong Macbook' you'd get both clients. This because 'Samuel Thomson' and his orders are stored altogether, i.e. ['Strong' 'Thinkpad' 'Light' 'Macbook'], there is no distinction between the two orderlines.
By using parent child documents, the orderlines for the same client are not mixed and preserve their identity.

Drupal Views Complex Grouped Filters

I have a Math Expression ($field_a - $field_b) that I want to create an exposed grouped filter for (select-list) so that I can effectively filter out my results.
How can I set this up so that users will be give two options based on the values of two field?
I ended up creating a custom field handler for this purpose.

Resources