Please, give an easy example how to execute query. I found some examples on the net but they are not working.
Like
GraphqlClient client = new GraphqlClient("example.com\graphql");
String query = "query {getClient(condition){clientName, clientID}}"
var response = client.executeQuery(query);
This should work fine:
var graphQLOptions = new GraphQLHttpClientOptions
{
EndPoint = new Uri("example.com\graphql", UriKind.Absolute),
};
var graphQLClient = new GraphQLHttpClient(graphQLOptions, new NewtonsoftJsonSerializer());
var msg = new GraphQLRequest
{
Query = "query {getClient(condition){clientName, clientID}}"
};
var graphQLResponse = await graphQLClient.SendQueryAsync<dynamic>(msg).ConfigureAwait(false);
Related
Using the .Net AWSSDK.EventBridge I created a rule:
var client = new AmazonEventBridgeClient();
string ruleName = "SomeRule";
var putRuleRequest = new Amazon.EventBridge.Model.PutRuleRequest()
{
Name = ruleName,
ScheduleExpression = "rate(10 minutes)",
State = RuleState.ENABLED
}
await client.PutRuleAsync(putRuleRequest);
var target = new Amazon.EventBridge.Model.Target();
target.Arn = "ARN_LAMBDA_FUNCTION";
target.Id = "LAMBDA_FUNCTION_NAME";
target.Input = JsonSerializer.Serialize(new { someId, someDate});
var targetList = new List<Amazon.EventBridge.Model.Target>();
targetList.Add(target);
var putTargetRequest = new Amazon.EventBridge.Model.PutTargetsRequest()
{
Rule = ruleName,
Targets = targetList
};
await client.PutTargetsAsync(putTargetRequest);
The Lambda function is already created so I put the ARN and name on the Target. The idea is that there is one function but multiple rules will call it.
The rule, schedule, and target to the function are created when I run the code but the problem is that the function can't be triggered by the rule. When I edit the rule, update it in the AWS Console without changing anything the trigger works.
What am I missing?
After searching through I found out I was missing the permission for Lambda.
//This line replaces the code above
var putRuleResponse = client.PutRuleAsync(putRuleRequest).Result;
var lp = new Amazon.Lambda.Model.AddPermissionRequest();
lp.FunctionName = FUNCTION_ARN;
lp.Action = "lambda:InvokeFunction";
lp.SourceArn = putRuleResponse.RuleArn;
lp.Principal = "events.amazonaws.com";
lp.StatementId = "SomeStatement";
var lambdaClient = new AmazonLambdaClient();
await lambdaClient.AddPermissionAsync(lp);
Query to scroll at the matching records from the query
this is the query of nest in C# to get all the records from nest C# find many questions which can solve it by using different method linq method but i want to do this this way any suggestions help would be appreciated
string[] MERCHANTNO = MerchantId.Split(",");
var mustClause = new List<QueryContainer>();
var filterClause = new List<QueryContainer>();
var filters = new List<QueryContainer>();
filters.Add(new TermsQuery{
Field = new Field("MERCHANTNO"),
Terms = MERCHANTNO,
});
Logger.LogInformation(clsName, funcName, "Filter Clause is:", filters);
var SearchRequest = new SearchRequest<AcquirerDTO>(idxName) {
Size = 10000,
SearchType = Elasticsearch.Net.SearchType.QueryThenFetch,
Scroll = "5m",
Query = new BoolQuery { Must = filters }
};
var searchResponse = await _elasticClient.SearchAsync<AcquirerDTO>( SearchRequest );
The code for Scroll all the Records you have in ElasticSearch is
Filter
filters.Add(new TermsQuery {
Field = new Field("MERCHANTNO"), >>> Value needs to be searched
Terms = MERCHANTNO,
});
Date Range Filter
filterClause.Add(new DateRangeQuery {
Boost = 1.1,
Field = new Field("filedate"),
GreaterThanOrEqualTo = DateMath.Anchored(yesterday),
LessThanOrEqualTo = DateMath.Anchored(Today),
Format = "yyyy-MM-dd",
TimeZone = "+01:00"
});
Search Request for scrolling
var SearchRequest = new SearchRequest<AcquirerDTO>(idxName) {
From = 0,
Scroll = scrollTimeoutMinutes,
Size = scrollPageSize,
Query = new BoolQuery
{
Must = filters,
Filter = filterClause
}
};
var searchResponse = await _elasticClient.SearchAsync<AcquirerDTO>(SearchRequest);
if (searchResponse.ApiCall.ResponseBodyInBytes != null) {
var requestJson = System.Text.Encoding.UTF8.GetString(searchResponse.ApiCall.RequestBodyInBytes);
var JsonFormatQuery = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(requestJson), Formatting.Indented);
}
This is the code for Scrolling all the results in kibana
List<AcquirerDTO> results = new List<AcquirerDTO>();
if (searchResponse.Documents.Any())
results.AddRange(searchResponse.Documents);
string scrollid = searchResponse.ScrollId;
bool isScrollSetHasData = true;
while (isScrollSetHasData)
{
ISearchResponse<AcquirerDTO> loopingResponse = _elasticClient.Scroll<AcquirerDTO>(scrollTimeoutMinutes, scrollid);
if (loopingResponse.IsValid)
{
results.AddRange(loopingResponse.Documents);
scrollid = loopingResponse.ScrollId;
}
isScrollSetHasData = loopingResponse.Documents.Any();
}
var records = results;
I am using CosmosDb Sdk with nuget Microsoft.Azure.DocumentDB.Core 2.1.0 with .NetStandard 2.0.
I am using this query to fetch documents
var client client = new DocumentClient(new Uri(config.CosmosDbEndPointUrl), config.CosmosDbPrimaryKey);
var partitionKey = "siteId"; // the partition key is defined as /siteId, I tried both, still not working
var queryOptions = new FeedOptions
{
MaxItemCount = 500,
EnableCrossPartitionQuery = true,
PartitionKey = new PartitionKey(partitionKey)
};
var auditQuery = client
.CreateDocumentQuery<AuditDTO>(
UriFactory.CreateDocumentCollectionUri(_databaseName, _collectionName), queryOptions)
.Where(f => f.Status == AuditStatus.Pending)
.AsDocumentQuery();
var results = new List<AuditDTO>();
while (auditQuery.HasMoreResults)
{
var audits = await auditQuery.ExecuteNextAsync<AuditDTO>();
results.AddRange(audits);
}
This query returns 0 document.
I based my query on this tutorial
I thought some parameters were incorrect so, I tried to use the Rest Api, code based on this example (see comment EXECUTE a query)
var client = new System.Net.Http.HttpClient();
string response = string.Empty;
string authHeader = string.Empty;
string verb = string.Empty;
string resourceType = string.Empty;
string resourceId = string.Empty;
string resourceLink = string.Empty;
client.DefaultRequestHeaders.Add("x-ms-date", utc_date);
client.DefaultRequestHeaders.Add("x-ms-version", "2017-02-22");
verb = "POST";
resourceType = "docs";
resourceLink = $"dbs/{databaseId}/colls/{collectionId}/docs";
resourceId = (idBased) ? $"dbs/{databaseId}/colls/{collectionId}" : collectionId.ToLowerInvariant();
authHeader = GenerateMasterKeyAuthorizationSignature(verb, resourceId, resourceType, masterKey, "master", "1.0");
client.DefaultRequestHeaders.Remove("authorization");
client.DefaultRequestHeaders.Add("authorization", authHeader);
client.DefaultRequestHeaders.Add("x-ms-documentdb-isquery", "True");
client.DefaultRequestHeaders.Add("x-ms-documentdb-query-enablecrosspartition", "true");
client.DefaultRequestHeaders.Add("x-ms-partition-key", "[\"siteId\"]");
var qry = new SqlQuerySpec { query = "SELECT * FROM root WHERE (root[\"status\"] = 0)" };
var r = await client.PostWithNoCharSetAsync(new Uri(baseUri, resourceLink), qry);
var s = await r.Content.ReadAsStringAsync();
Using the Rest Api returns 1 document as I am expecting.
I tried to deserialize the response to the class AuditDTO, it works, so, no problem with my model.
I don't understand why the Rest Api is working and not the .Net Sdk.
There is no authorization exception, no error message. I just get 0 document.
I am missing something?
var partitionKey = "siteId";
var queryOptions = new FeedOptions
{
MaxItemCount = 500,
EnableCrossPartitionQuery = true,
PartitionKey = new PartitionKey(partitionKey)
};
Your problem is on the partition key.
Partition key is expected to be the value of the partition key not the definition.
This means that the partitionKey value on FeedOptions should look like this 59c49da3-b398-4db7-aff4-d2129353e3a8 (assuming it's a guid) not this siteId.
The correct FeedOptions Object would look like this:
var partitionKey = "59c49da3-b398-4db7-aff4-d2129353e3a8";
var queryOptions = new FeedOptions
{
MaxItemCount = 500,
EnableCrossPartitionQuery = true,
PartitionKey = new PartitionKey(partitionKey)
};
The documentation is really misleading.
To enable CrossPartition queries to query all partitions, you just need to set EnableCrossPartitionQuery to true and that's it!
var queryOptions = new FeedOptions
{
MaxItemCount = 500,
EnableCrossPartitionQuery = true
};
As Nick Chapsas said, if you need to search a specific partition, set the PartitionKey property to the value of the partition you want to search against.
Here is a sample I found on Azure GitHub.
How can we achieve to get the result from dynomodb using two parameter? I am using below code it's does not work.
var _request = new QueryRequest
{
TableName = "Attendence",
KeyConditionExpression = "Roster_EmpID = :Roster_EmpID and Roster_CreatedDateTime between :v_start and :v_end",
ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
{":Roster_EmpID", new AttributeValue { S = result.empId }}
,{":v_start", new AttributeValue { S = result.fromDate.ToString(AWSSDKUtils.ISO8601DateFormat) }}
,{":v_end", new AttributeValue { S = result.toDate.ToString(AWSSDKUtils.ISO8601DateFormat) }}
},
IndexName = "Roster_EmpID-index"
};
var _response = await _client.QueryAsync(_request);
But it's not return the result, Please help me to get the result. I already wasted 2 days, still not able to find the answer.
I think you may looking for FilterExpression
KeyConditionExpression = "Roster_EmpID = :Roster_EmpID ",
FilterExpression = "Roster_CreatedDateTime between :v_start and :v_end",
I'm trying to perform a very simple mongodb mapreduce with c# 2.3 driver but i'm getting an exception:
The code is:`
string StringDeConexao = "mongodb://10.0.0.211:27017";
MongoClient client = new MongoClient(StringDeConexao);
var servidor = client.GetDatabase("distribuicoes");
var collection = servidor.GetCollection<BsonDocument>("processo");
var mapa = new BsonJavaScript(#"function() {
var chave = this.Natureza;
var valor = {
this.NumeroDoProcesso,
this.Comarca,
this.Natureza,
this.Classe,
this.Assunto.AssuntoPrincipal,
this.Autor.Nome,
this.Autor.TipoDePessoa,
this.CodigoCnaeAutor,
this.Reu.Nome,
this.Reu.TipoDePessoa,
this.CodigoCnaeReu,
count:1
};
emit(chave, valor);
};");
var reducao = new BsonJavaScript(#"function(chave, valores) {
var ObjetoReduzido = {
Natureza: chave,
count: 0
};
valores.ForEach(function(valor) {
ObjetoReduzido.count+= valor.count;
};
return Objeto.Reduzido;
};");
var pesquisa = Builders<BsonDocument>.Filter.Regex("Natureza", new BsonRegularExpression("c[iĆ]vel", "i"));
var option = new MongoDB.Driver.MapReduceOptions<BsonDocument, String>();
option.Filter = pesquisa;
option.OutputOptions = Inline;
var result = collection.MapReduce(mapa, reducao, option);`
It works on mongodb shell.
Thank's for any help.
Your ForEach() is (was) mal-formed and you have (had) trailing semicolons on each of the functions.