Search ElasticSearch via GET using JSON - json

Anyone know of a way to send a JSON query to an ElasticSearch server via HTTP GET? I know you can POST the JSON content to _search, but POST is not available because this is cross-domain. For example, if my query looks like this:
{
"query": {
"query_string": {
"fields": ["name", "description"],
"query": "Elastic Search"
}
}
}
Which I would convert to something like:
{"query":{"query_string":{"fields":["name","description"],"query":"Elastic Search"}}}
Is there a way to GET server:9200/index/type/_search?content=stringifiedquery or something similar? I've tried q= and content= as well as just passing the content after the ? but nothing seems to work. Anyone have any ideas? Or am I just out of luck?

You can use the source query string parameter to send what would normally be the post body.
See the bottom of this page: http://www.elasticsearch.org/guide/reference/api/

Related

How to save a JSON-object and use it in another request?

i'm currently trying to set up some JMeter testplans. I am pretty new to this (started a week ago) and don't have much programming experience either, so i hope you could help me in this case.
I already set up some http requests and have some simple JSON Extractor post processors to save some of the variables and use them with the "${variable}" notation.
But now i need to save and modify an object from a response to use that in the next http request.
My respose is a extremely big JSON object and the part im interested in looks something like this:
{
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
}
Note that for whatever reason these objects {"part":"1"...} are inside a nested array. And they are also pretty big.
I would like to safe those objects in a variable to use them in my next http request which should looks like this:
{
"instanceChange": {
"functionChecks": [
{"part": "1"...},
{"part": "2"...},
...
{"part": "20"...}
]
}
}
So what im really trying to find is a way to save all of the possible objects inside the nested array "resultInstance" and put them inside the non nested array "functionChecks".
I already looked inside the JMeter documentation but because of my poor programming background i cant find a way to realize this.
I think i need something like the JSR223 PostProcessor and "simply go through the resultInstance-array and use smth. like an getObject() on these", but i cant figure out the code i need and if its even possible to safe objects in variables in Jmeter.
Im pretty thankful for every bit of help or advice :).
Thanks in advance,
aiksn
Add JSR223 PostProcessor as a child of the request which returns the JSON response
Put the following code into "Script" area:
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def request = ['instanceChange': ['functionChecks': response.payload.workspace.resultInstance]]
vars.put('request', new groovy.json.JsonBuilder(request).toPrettyString())
That's it, you should be able to refer the generated request body as ${request} where required
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
let response ={
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
};
let requestObj={
"instanceChange": {
"functionChecks": [
]
}
};
response.payload.workspace.resultInstance.forEach(myFunction);
myFunction(item, index) {
requestObj.instance.functionsCheck.push(item[0]);
}

Json response with like array in array

I am sure for most of you is that maybe basic. But I did not found anything in Internet, and do not understand how to handle it.
I have no problem's to deal with JSON if I have something like
{"ReplyData":
[
{
"Lane": [],
"Id": 10000,
"Title": "atitle",
...
I am just asking in my code like: parse.ReplyData[0].Lane[0]
or parse.ReplyData[0].Id etc. and that works with out problems.
But now I have the follow situation (it is like an array in array):
{"ReplyData":
[
[
{
"Lane": []
...
it works with Postman and I receive my results there!
But I am not sure how to handle it within my googlescript with parse.ReplyData[].
If I try: params.ReplyData[0].Lane I get "undefined".
If I try params.ReplyData[0][0].Lane I get TypeError: Cannot read property "Lane" from undefined.
tried even params.ReplyData[0,0].Lane
Any Ideas? Thank you in advance

Facebook API - Batch upload photos

I'm trying to batch upload photos and I keep getting a response back from Postman saying "Batch parameter must be a JSON Array" Does anyone see what is wrong with this because it looks like valid json to me. I've been rattling with this for a few hours making minor tweaks trying to get it to upload to no avail. I also have tried encoding the url.
https://graph.facebook.com/v2.11?batch=[{"method":"POST", "relative_url":"https://graph.facebook.com/v2.11/{pageid}/photos?access_token={access-token}", "body":"link_url":"https://{link-to-image}/wmphotos/999995/6d5cc4169bbf4e7dbe31f3739e025412/a572c29dff_640.jpg"}]&access_token={access-token}
Looking at your code, it seems that the JSON object in your batch array is actually malformed. body:link_url:link should be body: {link_url:link}
Bad:
[
{
"method":"POST",
"relative_url":"foo",
"body":"link_url":"link"
}
]
Good:
[
{
"method":"POST",
"relative_url":"foo",
"body":{"link_url":"link"}
}
]

Cannot update fulfillment in Shopify

I have this: PUT/admin/orders/450789469/fulfillments/255858046.json in updating the fulfillment.
I have this following json data to update:
{ "fulfillment": {"id":3604167143,"order_id":4015640143,"status":"success","tracking_numbers":"6J700123456","variant_inventory_management":"shopify"}}
It returns a 400 error - Bad request.
Is there anything I've missed in passing the data to update? Thanks.
You'll want to send tracking_numbers as an array, rather than a string. Try something like this:
{
"fulfillment": {
"id": 3604167143,
"order_id": 4015640143,
"status": "success",
"tracking_numbers": ["6J700123456"],
"variant_inventory_management": "shopify"
}
}
If you look in the body of the response from Shopify then you can sometimes find more info about what went wrong.

Empty response after sending request to couchDB

I've got problem with CouchDB request. Record from view looks like:
{
"total_rows":79293,
"offset":0,
"rows":[
{"id":"401417608421000",
"key":["2015-08-03T12:07:01+0000"],
"value":0}]
}
request looks like:
http:/ip:port/testDB/_design/reports/_view/experiments?key=["2015-08-03T12:07:01+0000"]
it returns
{
"total_rows":79382,
"offset":0,
"rows":[ ]
}
I read https://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
and change url to
http:/ip:port/testDB/_design/reports/_view/experiments?key=%5B%222015-08-03T12:0‌​7:01+0000%22%5D
but it didn't helped.
Directly I want to send request with startDate and endDate.
It's the plus sign that is making the query fail. If you encode the url you should at least try to encode the entire parameter, this works for me:
?key=%5B"2015-08-03T12%3A07%3A01%2B0000"%5D
And after a bit of testing I found the plus sign to be the problem, so a prettier key-parameter looks like this and works for me:
?key=["2015-08-03T12:07:01%2B0000"]