I want to group by particular column whose count is equal to some input number.
my query:
Criteria countCriteria = Criteria.where("count").is(2);
if(!criteria.getCriteriaObject().keySet().isEmpty()){
countCriteria.andOperator(criteria);
}
criteria: Criteria Object what I get as input
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.group(MBR_REWARD_ENROLL_NUM).count().as("count"),
Aggregation.match(countCriteria)
);
If I pass some Criteria to 'criteria' object, it is not working. If I don't pass anything, then it is working. Could somebody help me?
Related
I used to use Milvus1.0. And I can get all IDs from Milvus1.0 by using get_collection_stats and list_id_in_segment APIs.
These days I am trying Milvus2.0. And I also want to get all IDs from Milvus2.0. But I don't find any ways to do it.
milvus v2.0.x supports queries using boolean expressions.
This can be used to return ids by checking if the field is greater than zero.
Let's assume you are using this schema for your collection.
referencing: https://github.com/milvus-io/pymilvus/blob/master/examples/hello_milvus.py
as of 3/8/2022
fields = [
FieldSchema(name="pk", dtype=DataType.INT64, is_primary=True, auto_id=False),
FieldSchema(name="random", dtype=DataType.DOUBLE),
FieldSchema(name="embeddings", dtype=DataType.FLOAT_VECTOR, dim=dim)
]
schema = CollectionSchema(fields, "hello_milvus is the simplest demo to introduce the APIs")
hello_milvus = Collection("hello_milvus", schema, consistency_level="Strong")
Remember to insert something into your collection first... see the pymilvus example.
Here you want to query out all ids (pk)
You cannot currently list ids specific to a segment, but this would return all ids in a collection.
res = hello_milvus.query(
expr = "pk >= 0",
output_fields = ["pk", "embeddings"]
)
for x in res:
print(x["pk"], x["embeddings"])
I think this is the only way to do it now, since they removed list_id_in_segment
So i have a small test collection that has this format...
Sample Data
I have created a simple query that returns an array with all the ids..
All_Ids = db.Test_Collection.find({}, {_id:1}).map(function(item){ return item._id; })
[ 98800754, 15301328, 76812898 ]
And i Want to take in an inputted id and check to see if that inputted value is present in the array..
here was my initial attempt..
> query_Figure = 98800754
98800754
> db.Test_Collection.find({query_Figure: {$in: All_Ids}})
I tried using the $in operator to find that specific value.. with the array and specific id to be searched as variables, but had no luck as the query returned nothing, when the value im searching for is clearly in the array
As you can tell I am a newbie and would appreciate some help in improving the query!
$in operator returns the documents in which value of the specified field is present in the array.
In your case, since query_Figure is not a field in any of your documents, your query returns no matching documents.
If you just want to check if the input id is present in the All_Ids array, then you don't need a query. Just use Array.prototype.includes()
const exists = All_Ids.includes(query_Figure);
My goals are as simple as:
group my data by an attribute and count how many elements are in each group.
count how many distinct values are in a field.
Can I do these 2 things in DynamoDB?
1) group my data by an attribute and count how many elements are in each group.
GROUP BY function is not supported by DynamoDB at the moment. You need to Scan or Query the table and implement it yourself.
2) Count how many distinct values are in a field
There is no distinct function available in Dynamodb either. However, you can get the scanned count and actual count. Please refer this link.
Another thread
ScannedCount — the number of items that were queried or scanned,
before any filter expression was applied to the results. Count — the
number of items that were returned in the response.
I have the following:
43 documents indexed in Solr
If I use the Java API to do a query without any grouping, such as:
SolrQuery query = new SolrQuery("*:*");
query.setRows(10);
I can then obtain the total number of matching elements like this:
solrServer.query(query).getResults().getNumFound(); //43 in this case
The getResults() method returns a SolrDocumentList instance which contains this value.
If however I use grouping, something like:
query.set("group", "true");
query.set("group.format", "simple");
query.set("group.field", "someField");
Then the above code for retrieving query results no loger works (throws NPE), and I have to instead use:
List<GroupCommand> groupCommands = solrServer.query(query).getGroupResponse().getValues();
List<Group> groups = groupCommand.getValues();
Group group = groups.get(groupIndex);
I don't understand how to use this part of the API to get the overall number of matching documents (the 43 from the non-grouping query above). First I thought that with grouping is no longer possible to get that, but I've noticed that if I do a similar query in the Solr admin console, with the same grouping and everything, it returns the exact same results as the Java API and also numFound=43. So obviously the code used for the console has some way to retrieve that value even when grouping is used:
My question is, how can I get that overall number of matching documents for a query using grouping executed via Solr Java API?
In looking at the source for Group that is returned from your groups.get(groupIndex) call, it has a getResults() method that returns a SolrDocumentList. The SolrDocumentList has a getNumFound() method that should return the overall number, I believe...
So you should be able to get this as the following:
int numFound = group.getResults().getNumFound();
Hope this helps.
Update: I believe as OP stated, group.getResults().getNumFound() will only return the number of items in the group. However, on the GroupCommand there is a getMatches() method that may be the corresponding count that is desired.
int matches = groupCommands.getMatches();
If you set the ngroups parameter to true (default false) this will return the number of groups.
eg:
solrQuery.set("group.ngroups", true);
https://cwiki.apache.org/confluence/display/solr/Result+Grouping
this can then be retrieved from your responding GroupCommand with:
int numGroups = tempGroup.getNGroups();
At least that was my understanding?
I am using solrnet 0.40 grouping functionality.
And I am grouping on a single field (say filename).
But in the results I would like to display multiple hits for the group (filename).
FileName-1
hit-1, hit-2....hit-n
FileName-2
hit-1, hit-2....
and so on....
Is there any way grouping gives me the functionality to get results clustered other than the obvious way of running a secondary query for each group?
TIA
Just needed to set the grouping params to desired value. For example, have set it to 10 to get 10 results per group.
Grouping = new GroupingParameters()
{
Fields = new [] { "manu_exact" },
Format = GroupingFormat.Grouped,
Limit = 10,
}