wildcards in cloudant query json - wildcard

I have created a cloudant Query index --json, for a field in a cloudant DB. But I am not able to use the wildcards in the selector of the cloudant query.
ex:
priority field can take the values a,b,c,d,e,f...z
In the selector below I am trying to retrieve all the records in the DB and then sort it on priority itself.. but when I use the wildcards, it is not returning results at all.
{
"selector": {
"priority":"*"
},
"sort": [
{
"priority": "asc"
}
]
}
Please tell me which wildcard need to be used to retrieve all the docs

you may want to try using the $regex selector
{
"selector": {
"_id": {
"$gt": 0
},
"priority": {
"$regex": ".*"
},
"sort": [
{
"priority": "asc"
}
]
}
}
additional information about $regex can be found here:
https://docs.cloudant.com/cloudant_query.html#creating-selector-expressions

Related

How to retrieve firebase documents missing a field using runQuery and the IN operator?

This is my http POST requst body...
{
"structuredQuery": {
"select": {
"fields": [
{
"fieldPath": "name"
},
{
"fieldPath": "taxId"
},
{
"fieldPath": "mailingAddress"
}
]
},
"from": [
{
"collectionId": "orgs"
}
],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "orgId"
},
"op": "IN",
"value": {
"arrayValue": {
"values": [
{
"stringValue": ""
},
{
"nullValue": null
}
]
}
}
}
}
}
It fails to return orgs where the orgId field is completely missing from the document. It correctly includes orgs where the orgId field is present and equal to empty string. This is accessing a Cloud Firestore db.
Due to the way Firestore indexes data, it is not possible to query for documents for which a certain field "is completely missing from the document": the field needs to exist in order for the Firestore index to take it into account. More details on the indexing mechanism in the following official video.
You may store an empty value in this field, as you mention in your question.

Firebase Firestore REST Request - Query and Filter

I have a firestore database on a firebase project. I want to make rest request for filtering or querying data with postman. I'm using "https://firestore.googleapis.com/v1/projects//databases/(default)/documents/" to get the data in a known path in my database. Here is a sample of my database structure:
users > xxxxx > messages > yyyyy> "sent":"true"
where "users" and "messages" are collections, "xxxxx" and "yyyyy"are autogenerated document ids (xxxxx is autogenerated user id)
What I want to do is to find the "xxxxx"s (users) which have >"sent":"true"< data.
I get success if I know the "xxxxx" and "yyyyy" but I don't know them because they are autogenerated and different from each other in my database and don't know how to do it.
You need to run a Query, as explained here in the documentation of the REST API.
Since you want to query all the messages sub-collections of different user documents, you need to "simulate" a Collection Group Query in your StructuredQuery. The way to do that is to set the allDescendants element to true in the CollectionSelector.
So, issuing a POST HTTP Request on the following URL will do the trick:
var URL = "https://firestore.googleapis.com/v1/projects/<your-project-id>/databases/(default)/documents:runQuery";
The body of the POST Request shall contain:
"structuredQuery": {
"from": [{
"collectionId": "messages",
"allDescendants": true
}],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "sent"
},
"op": "EQUAL",
"value": {
"stringValue": "true",
}
}
}
}
Note that you need to add a single field index to your Firestore DB, as follows:
Note also that, if your field sent is of type Boolean (and not String as shown in your question), you need to use a booleanValue element in your Value JSON element.
I am unable to get this to work for some reason.
I have a Collection called dzs which has some documents with auto generated id's.
I want to query and find a document with a specific email address.
When I try this in Postman, it returns (Error 400 Bad request)
"structuredQuery": {
"from": [{
"collectionId": "dzs",
"allDescendants": true
}],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "email"
},
"op": "EQUAL",
"value": {
"stringValue": "123#123.com",
}
}
}
}
Add the parent collection/document path to the URL:
var URL = "https://firestore.googleapis.com/v1/projects/<your-project-id>/databases/(default)/documents/users/xxxxx:runQuery";
Then make the collectionId "messages" and allDescendents false:
"structuredQuery": {
"from": [{
"collectionId": "messages",
"allDescendants": false
}],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "sent"
},
"op": "EQUAL",
"value": {
"stringValue": "true",
}
}
}
}
Source

Want to fetch latest record from the list of records in kibana using DSL query

We are using the ELK v6.6 version.
We have requirement in Kibana that we have list of records which are displaying in the Kibana data table. We need to display last updated record on top of the table. For which we are using below DSL query but which is not working.Can you please help us to resolve this issue.
{
"query": {
"match_all": { }
},
"aggs": {
"actual_trans_type.keyword": {
"terms": {
"field": "#timestamp"
},
"aggs": {
"top_hit": {
"sort": [
{
"fieldName": {
"order": "desc"
}
}
],
"size": 2
}
}
}
}
}
https://i.stack.imgur.com/eCpde.png
https://i.stack.imgur.com/9XBHC.png
Edit the visualization, click on the timestamp column head to sort it in the descending order and then save the visualization. Now you will have the table in the descending order of timestamp field by default.

Request probleme with Google Cloud Datastore and Filter

I'm currently doing some tests on google datastore, but I'm having a problem with my queries.
If I believe in the documentation https://cloud.google.com/datastore/docs/concepts/queries we can realize a filter on several columns with the instruction EQUALS.
But when testing, I get an error from the API.
While searching on Datastore's github, I found this reference: https://github.com/GoogleCloudPlatform/google-cloud-dotnet/issues/304 which corresponds to my problem, except that for my case the query to the look good.
Here is the request sent:
{
{
"kind": [{
"name": "talk.message"
}],
"filter": {
"compositeFilter": {
"op": "AND",
"filters": [{
"propertyFilter": {
"property": {
"name": "Conversation"
},
"op": "EQUAL",
"value": {
"stringValue": "2f16c14f6939464ea687d316438ad4cb"
}
}
},
{
"propertyFilter": {
"property": {
"name": "CreatedOn"
},
"op": "LESS_THAN_OR_EQUAL",
"value": {
"timestampValue": "2019-03-15T10:43:31.474166300Z"
}
}
},
{
"propertyFilter": {
"property": {
"name": "CreatedOn"
},
"op": "GREATER_THAN_OR_EQUAL",
"value": {
"timestampValue": "2019-03-14T10:43:31.474175100Z"
}
}
}
]
}
}
}
}
And here is the answer from the API:
{Grpc.Core.RpcException: Status(
StatusCode=FailedPrecondition,
Detail="no matching index found. recommended index is:
- kind: talk.message
properties:
- name: Conversation
- name: CreatedOn"
)
According to the documentation, this should be good... but it's not !
What am I missing ?
Your query includes both an EQUALS (on Conversation) and a non-EQUALS filter (on CreatedOn), therefore you need a composite index to fulfil the query. So your query is valid, but it needs a composite index to be able to run the query.

Refs to # in a definition don't parse inJson.net schema

I have a schema that has a 'manager' property which is a user object:
{
"id": "foo.com/schemas/user",
"manager": {
"anyOf": [{
"$ref": "#/definitions/user"
}],
"title": "Manager"
}
The #/definitions/user schema is:
"definitions": {
"user": {
"$ref": "#"
}
}
This results in a "Error when resolving schema reference '#'. Path 'definitions.user'" error.
Addressing the user with "$ref": "#" from the manager property isn't an option as we are using the definition to help build the UI and need a common definition.
Edit: added the "id" property which was a critical omission in this.
This works:
{
"id": "http://foo.com/schemas/user",
"properties":{
"manager":{
"anyOf":[
{
"$ref":"#/definitions/user"
}
],
"title":"Manager"
}
},
"definitions":{
"user":{
"$ref":"#"
}
}
}
https://github.com/JamesNK/Newtonsoft.Json.Schema/issues/33
Edit: Added fixed "id" field with http:// qualification added.

Resources