How can I let Elasticsearch accept multiple json in one request? - elasticsearch

I am using Elasticsearch7 and create a pipeline based on https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html.
The pipeline is to decode base64 like below:
{
"version": 1,
"processors": [
{
"script": {
"source": "ctx.decoded = ctx.data.decodeBase64();"
}
},
{
"json": {
"field": "decoded",
"add_to_root": true
}
},
{
"remove": {
"field": "decoded"
}
}
]
}
I receive error when I push data to the index:
Response for request ff6dd42a-5694-4c17-b103-c37bae72af58 is not recognized as valid JSON or has unexpected fields. Raw response received: 400 {\"error\":{\"root_cause\":[{\"type\":\"script_exception\",\"reason\":\"runtime error\",\"script_stack\":[\"ctx.decoded = ctx.data.decodeBase64();\",\" ^---- HERE\"],\"script\":\"ctx.decoded = ctx.data.decodeBase64();\",\"lang\":\"painless\",\"position\":{\"offset\":22,\"start\":0,\"end\":38}}],\"type\":\"script_exception\",\"reason\":\"runtime error\",\"script_stack\":[\"ctx.decoded = ctx.data.decodeBase64();\",\" ^---- HERE\"],\"script\":\"ctx.decoded = ctx.data.decodeBase64();\",\"lang\":\"painless\",\"position\":{\"offset\":22,\"start\":0,\"end\":38},\"caused_by\":{\"type\":\"null_pointer_exception\",\"reason\":\"Cannot invoke \\\"Object.getClass()\\\" because \\\"callArgs[0]\\\" is null\"}},\"status\":400}
The reason is that the json is not a single one. It is a multiple json data:
{
"data": "..."
}
{
"data": "..."
}
They are not valid json array so how can I let Elasticsearch piepline accepts this format?

Related

Wiremock request.query not working with a paramter that contains dots

I'm using sprint-boot with wiremock-jre8, what i'm trying to to is to get a value from URL params, but this value contains dots "product.productCharacteristic.value"
{
"request": {
"urlPath": "/exampleOfPath",
"method": "GET",
"queryParameters": {
"product.productCharacteristic.name": {
"equalTo": "MSISDN"
},
"product.productCharacteristic.value": {
"matches": ".*"
}
}
},
"response": {
"status": 200,
"jsonBody": {
"key": "the value should be here {{request.query['product.productCharacteristic.value']}}"
},
"transformers": [
"response-template"
],
"headers": {
"Content-Type": "application/json"
}
}
}
i have tested all of those
{{request.query.['product.productCharacteristic.value']}}
{{request.query['product.productCharacteristic.value']}}
{{request.query['product%2EproductCharacteristic%2Evalue']}}
{{request.query.['product%2EproductCharacteristic%2Evalue']}}
{{request.query.product%2EproductCharacteristic%2Evalue}}
{{request.query.product.productCharacteristic.value}}
{{lookup request.query 'product.productCharacteristic.value'}}
{{lookup request.query 'product%2EproductCharacteristic%2Evalue'}}
You can use this format:
{{request.query.[product.productCharacteristic.value]}}
See WireMock - Response Templating - The request model:
request.headers.[<key>] - Header with awkward characters e.g. request.headers.[$?blah]

Changing the structure of an output JSON of GraphQL

In GraphQL, is it possible to have the output JSON in a different structure than the input data/JSON?
Ex: Below is the Data/input JSON on which query will be executed
{
"BatchId": 1897173,
"ApprovalCode": "12528809",
"ResponseCode": 0,
"ResponseMessage": "PENDING"
}
and the expected output after query is executed to be
{
"Batch": {
"id": 1897173
},
"ApprovalCode": "12528809",
"Response": {
"ResponseCode": 0,
"ResponseMessage": "PENDING"
}
}

Why does FaunaDB output differ from Graphqli?

I have created a simple user.gql file
type Query {
users: [user]
userById(id:ID!):user
}
type user {
id: ID!
chat_data: String
}
My data is
[
{
"id": "0815960b-9725-48d5-b326-7718c4749cf5",
"chat_data": ""
}
]
When I run this on my local server and use the query
{users{id}}
I see the expected output
{
"data": {
"users": [
{
"id": "0815960b-9725-48d5-b326-7718c4749cf5"
}
]
}
}
I have created a user collection on FaunaDB with the data
{
"ref": Ref(Collection("user"), "324407037973758152"),
"ts": 1645691670220000,
"data": {
"id": "0815960b-9725-48d5-b326-7718c4749cf5",
"chat_data": ""
}
}
and uploaded my user.gql, but when I run the GraphQl query
{users{id}}
I get the error
{
"data": null,
"errors": [
{
"message": "Cannot query field 'id' on type 'userPage'. (line 3, column 5):\n id\n ^",
"locations": [
{
"line": 3,
"column": 5
}
]
}
]
}
What am I doing wrong?
This is very unintuitive, but Fauna seems to be returning a paginated result. Read more about it here.
The best thing would be to GraphiQL to have a look at the schema of the Fauna GraphQL endpoint. Autocomplete should also work when you look for fields to query. The error basically says that you can't query the id directly. Try this:
{ users { data { id } } }

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"})

How to partial match response in the artillery tool?

I am using artillery tool for websocket testing. The problem I am facing is with response. After emitting data to the channel that I am testing, we always get different data. As artillery's Response block tries to match completely with the actual response from the channel (i.e It doesn't match partially) , I am always getting a error 'data is not valid: 1'. How to match partially the response?
Below response code is working.
{
"response": {
"channel": "channel1",
"match": [
{
"json": "$.Id",
"value": "test_101"
},
{
"json": "$.param1",
"value": "1"
},
{
"json": "$.param2",
"value": "XXX"
},
{
"json": "$.param3",
"value": "100"
}
]
}
}

Resources