RestHeart passing multiple parametrs in aggregation - spring

Basically I am trying to use REST hreat to create two variables issuerId and sectionName. I am trying to get data from the URI mentioned below
http://ftc-wbpyrdb201:8080/statdata/InsStatData/_aggrs/getDataByIssuerAndSectionName?avars={"issuerId":19038},{"sectionName":"ASSETS"}
My aggregation definition is a below
{"$push" : {
"aggrs":
{
"type": "pipeline",
"uri": "getDataByIssuerAndSectionName",
"stages": [
{
"_$match": {
"_$and": [
{"issuerId": {"_$var": "issuerId" }},
{
"sectionName": {"_$var": "sectionName"}
}
]
}
},
{
"_$unwind": "$sections"
},
{
"_$unwind": "$sections.data"
},
{
"_$unwind": "$sections.data.values"
},
{
"_$match": {
"_$and": [
{"issuerId": {"_$var": "issuerId" }},
{
"sectionName": {"_$var": "sectionName"}
}
]
}
}
]
}
}
}
I am sure I am doing something wring in either defining the aggregation or while requesting the URI. There is not enough in the documentation. Please help me with this request.

Related

Simplify Contentful GraphQL query result

I am using the following graphql query to get the header from Contentful:
{
header {
name
navigationCollection {
items {
name
}
}
}
}
And this is the result I get:
{
"header"
"name": "Main Header"
"navigationCollection": {
"items" : [
{
"name": "nav1",
},
{
"name": "nav2",
}
]
}
}
I wonder if there is way to simplify the GraphQL query result to produce something like this :
{
"header"
"name": "Main Header"
"navigationItems": [
{
"name": "nav1",
},
{
"name": "nav2",
}
]
}

ElasticSearch cannot convert from string to ElasticClient.searchRequestparameters

This is the Json variable this filter is working fine in kibana dashbaord here is the screenshot for that
My Requirement is that want to get the same output as am getting from Kibana using filter query from Elastic Search Dot net Search Request here is the link which i followed from stack over flow to the point where get till now
{
""version"": true,
""size"": 500,
""sort"": [
{
""AddedOn"": {
""order"": ""desc"",
""unmapped_type"": ""boolean""
}
}
],
""stored_fields"": [
""*""
],
""script_fields"": { },
""docvalue_fields"": [
{
""field"": ""#timestamp"",
""format"": ""date_time""
},
{
""field"": ""AddedOn"",
""format"": ""date_time""
}
],
""_source"": {
""excludes"": []
},
""query"": {
""bool"": {
""must"": [],
""filter"": [
{
""match_all"": { }
},
{
""match_all"": { }
},
{
""bool"": {
""filter"": [
{
""match_all"": { }
},
{
""match_all"": { }
},
{
""range"": {
""AddedOn"": {
""format"": ""strict_date_optional_time"",
""gte"": ""2019-10-26T09:20:14.087Z"",
""lte"": ""2020-10-26T09:20:14.087Z""
}
}
}
],
""must"": [],
""must_not"": [],
""should"": []
}
},
{
""range"": {
""AddedOn"": {
""gte"": ""2019-10-26T10:38:34.169Z"",
""lte"": ""2020-10-26T10:38:34.170Z"",
""format"": ""strict_date_optional_time""
}
}
}
],
""should"": [],
""must_not"": []
}
},
""highlight"": {
""pre_tags"": [
""#kibana-highlighted-field#""
],
""post_tags"": [
""#/kibana-highlighted-field#""
],
""fields"": {
""*"": { }
},
""fragment_size"": 2147483647
}
}
"
This is the code which is doing searching in elasticsearch index
_elasticClient.LowLevel.Search<SearchResponse<object>>(FraudIndex, "type", json4); >>> The errror i am getting is that cannot convert from string to ElasticClient.searchRequestparameters
This was the solution found
var SearchResponse =await_elasticClient.LowLevel.SearchAsync<SearchResponse<object>>(FraudIndex, json4);

shorten the graphql field value

I am trying to fetch image path in an alias field using graphql, I am able to get output like this:
Output:
{
"data": {
"leaders": [
{
"partyImg": {
"image": {
"url": "/uploads/17a5f020cc974679ac52e56a22b74dd6.png"
}
}
},
{
"partyImg": {
"image": {
"url": "/uploads/70bd673d41654058847e39c14cda5fef.png"
}
}
},
{
"partyImg": {
"image": {
"url": "/uploads/c54a0ace0bb34da3985c67945b1d0bf0.png"
}
}
}
]
}
}
When I used the following graphql code:
Input:
query Leaders{
leaders{
partyImg: party{image: Image{ url }},
}
}
The output I am trying to get is:
Expected output:
{
"data": {
"leaders": [
{
"partyImg": "/uploads/17a5f020cc974679ac52e56a22b74dd6.png"
},
{
"partyImg": "/uploads/70bd673d41654058847e39c14cda5fef.png"
},
{
"partyImg": "/uploads/c54a0ace0bb34da3985c67945b1d0bf0.png"
}
]
}
}
Please help me to prepare the graphql input which could generate the expected output.
It appears the graphql schema prevents you from getting the data in the format that you want. Based on your input query, I expect the schema looks something like this:
query {
leaders: [Leader]
}
type Leader {
party: Party
}
type Party {
Image: Image
}
type Image {
url: String
}
To get the data in the format that you want, you would need a schema that looks more like:
query {
leaders: [Leader]
}
type Leader {
party: Party,
imageUrl: String
}
Then you could do:
query Leaders {
leaders {
partyImg: imageUrl
}
}
I assume you don't control the schema, so you would have to do post processing. If you are using javascript, the following could work for the above output as a simple mapping exercise.
(function() {
var output = {
"data": {
"leaders": [{
"partyImg": {
"image": {
"url": "/uploads/17a5f020cc974679ac52e56a22b74dd6.png"
}
}
},
{
"partyImg": {
"image": {
"url": "/uploads/70bd673d41654058847e39c14cda5fef.png"
}
}
},
{
"partyImg": {
"image": {
"url": "/uploads/c54a0ace0bb34da3985c67945b1d0bf0.png"
}
}
}
]
}
};
var transformed = {
data: {
leaders: output.data.leaders.map(function flattenUrl(item) {
return {
partyImg: item.partyImg.image.url
};
})
}
}
document.getElementById('transformedOutput').innerHTML = JSON.stringify(transformed);
}());
<div id="transformedOutput"></div>
If you are the author of this graphql schema, you can structure it in whatever way makes the most sense to your applications and/or consumers.

Is it possible to get rid of the 'data' ,'nodes', ... fields?

I have the following GraphQL query:
{
allForums {
nodes {
name,
topics: topicsByForumId(orderBy: [TITLE_ASC]) {
nodes {
title
}
}
}
}
}
This returns something as following:
{
"data": {
"allForums": {
"nodes": [
{
"name": "1",
"topics": {
"nodes": [
{
"title": "a"
},
{
"title": "b"
}
]
}
}
]
}
}
}
I would like to get the result below:
[
{
"name": "1",
"topics": [
{
"title": "a"
},
{
"title", "b"
}
]
}
]
Is it possible to get rid of the data, nodes, ... fields? Is that something that can be done within GraphQL, or should I do that in my service implementation?
I am using PostGraphile v4.2.0 as a GraphQL implementation, on top of PostgreSQL v11.
As indicated in the docs, you can expose a simpler interface for connections, or eliminate the default Relay-based connection interface altogether:
If you prefer a simpler list interface over GraphQL connections then you can enable that either along-side our connections (both) or exclusively (only) using our --simple-collections [omit|both|only] option.

prismic graphql querying single user

I'm trying to figure out how to query a single user from graphql schema by id. I'm using the graphiql tool and I'm able to get all Users.
{
allPrismicUsers {
edges {
node {
id
data {
name
}
}
}
}
}
Outputs :
{
"data": {
"allPrismicUsers”: {
"edges": [
{
"node": {
"id": "Prismic__User__WzKFwywAABmiZk_4",
"data": {
"name": “John Doe”
}
}
},
{
"node": {
"id": "Prismic__User__WzKDZywAABmiZkYp",
"data": {
"name": “Jane Doe“
}
}
},
{
"node": {
"id": "Prismic__User__WzKGDiwAAJSiZlFL",
"data": {
"name": “Cat Doe”
}
}
}
]
}
}
}
I also have prismicUser() on the schema
query {
prismicUser {
id
data {
name
}
}
}
Output:
{
"data": {
"prismicUser": {
"id": "Prismic__User__WzKGDiwAAJSiZlFL",
"data": {
"name": "Cat Doe"
}
}
}
}
I'm trying to query a user based on a specific id but not sure if I'm querying the wrong way.
I tried this.
query {
prismicLocation(id: "Prismic__User__WzKDZywAABmiZkYp") {
data {
name
}
}
}
I get an error
{ "errors": [
{
"message": "Argument \"id\" has invalid value \"Prismic__User__WzKDZywAABmiZkYp\".\nExpected
\"prismicUserIdQueryString_2\", found not an object.",
"users": [
{
"line": 25,
"column": 23
}
]
} ] }
How can I call a specific user based on their id ?
According to the Gatsby GraphQL reference, Gatsby allows you to filter results by any field in GraphQL (using operators such as eq, ne, etc.)
The gatsby-source-prismic plugin provides a field called prismicId (i.e. W1syKSIAAAzdN1Jg).
Here is an example query:
{
prismicUser(prismicId:{eq:"WzKDZywAABmiZkYp"}) {
data {
name
}
}
}
But you can also query by id:
prismicUser(id:{eq:"Prismic__User__WzKDZywAABmiZkYp"})

Resources