Different result when using GET/POST in elastic search - url

I am experimenting with elastic search via the Elastic Search Head plugin.
The results are as expected when I submit a query via POST.
However when I try the same query using GET, I always get back all values in the index.
So : how to pass the query to the elastic search server via GET so I can use the search string in an URL?

If you send a GET the body is probably not even sent to elasticsearch, so you are basically sending no query to the _search endpoint, which is why you are getting everything back (of course only the first 10 results based on the default size parameter).
Have a look at the URI request, which allows you to send basic queries using the q parameter within the URI. You can use the Lucene query syntax and specify some other parameters listed in the linked page. If you then want to execute more advanced queries, you might want to express them as JSON queries in order to get all the benefits of the elasticsearch Query DSL, but you'd need to provide them as body of the request.
UPDATE
Looking deeper at the elasticsearch head plugin, the query is not sent as the request body when you select the GET method but within the URL itself and without specifying the name for the parameter, like this:
http://localhost:9200/_search&{"query":{"term":{"text":"john"}}}
That is probably a bug in the plugin itself and elasticsearch can't find the query, that's why you get all the results back. That means that only the POST method works while sending queries with elasticsearch head.
Elasticsearch allows to use both GET and POST for executing queries. If you use GET you can either send the query as body or use the source parameter like this:
http://localhost:9200/_search?source={"query":{"term":{"text":"john"}}}

Related

Cannot bind query parameter; Unknown name basicRequest when retrieving basic insights for a location

I'm trying to retrieve insights for a location using the Google Business Profile API. I've tried a few approaches, but I always get an error about "Cannot bind query parameter".
According to the docs, I should be posting to this URL: https://mybusiness.googleapis.com/v4/accounts/xxx/locations:reportInsights
and in the body, pass in an array of locationNames, but when I do that, I get the error about "Cannot bind query parameter 'locationNames'".
So I just tried doing a GET on this URL and pass in the names on the name querystring and that worked just fine to get the high-level data.
https://mybusiness.googleapis.com/v4/accounts/xxx/locations:reportInsights?name=accounts/xxx/locations/xxx
So I know I have the right account ID, location ID, etc. But I need to be able to add in the basicRequest parameter so I can indicate which metric that I want to retrieve.
So I've POST to both of those URLS above with a body that looks like this:
{"basicRequest":{"metricRequests":[{"metric":"ALL"}],"timeRange":{"startTime":"2020-10-12T01:01:23.045123456Z","endTime":"2022-01-10T23:59:59.045123456Z"}}}
But again, I get the same errors about "Cannot bind query parameter" to field "basicRequest" (Same as when I tried to pass in the "locationNames" param in the JSON.
So clearly, I'm doing something wrong with how I am sending in the parameters in the body because it doesn't seem to think any of those parameter names are valid. My end goal is to be able to retrieve queries_direct, actions_total, etc.
I'm using Ruby, and there isn't a client library for it, so I'm just crafting the URLs and the JSON body and doing a GET or POST to it.
Greatly appreciate any pointers!

Walmart Paginated Products API

I am attempting to use the Paginated Products API to make a GET request using the optional specialOffer parameter. I have made many requests with multiple variations of the parameters available and have received an empty JSON object for each request whenever I use the specialOffer parameter. However, when I use the other optional parameters available without the specialOffer parameter, such as category, brand, format, and count, I receive the expected response.
Example requests that returns empty JSON object:
http://api.walmartlabs.com/v1/paginated/items?apiKey=APIKEY&specialOffer=specialBuy
http://api.walmartlabs.com/v1/paginated/items?apiKey=APIKEY&category=3944_1060825_1939756&specialOffer=specialBuy&count=10
Example request that returns expected results:
http://api.walmartlabs.com/v1/paginated/items?apiKey=APIKEY&category=3944_1060825_1939756&count=10
In addition to this, I have ensured that there are items available which are in the specialBuy (as well as rollback and clearance) categories, by checking the Special Feeds like so:
http://api.walmartlabs.com/v1/feeds/specialbuy?apikey=APIKEY&categoryId=3944_1060825_1939756
Documentation for the Paginated Products API:
https://developer.walmartlabs.com/docs/read/Paginated_Products_API
Can anyone shed some light on this issue?

Using Breeze query not invoking action

I am developing single page application using HotTowel.
My question is that, When I am writing a Breeze query with string parameter whose length is greater than 1600 characters then action is not invoking.
Please let me know the reason.
Thanks in advance.
as stated in:
What is the maximum length of a URL in different browsers?
there is a limit for the length of urls
check parametrized queries as a possible workaround:
How to properly send action parameter along with query in BreezeJs
The answer from #fops is correct. Using .withParameters, you may be able to create some methods on your server that allow you to use some shorthand on the client instead of very large queries.
If your queries are really big, and even .withParameters blows up your URL, you may need to use POST instead of GET.
Breeze doesn't support POST for queries directly, but there's an (unsupported) add-on in Breeze Labs called breeze.ajaxpost.js that will let you use POST for .withParameters queries.

Is there a way to see the string version of a parameterized cypher query?

In Ruby on Rails, using NeoGraphy, I'm constructing a parameterized cypher query and getting back a result.
#results = $neo.execute_query(query, parameters)
Using gon, I put all these to the client and checked them out in the javascript console:
gon.results = #results
gon.search_query = query
gon.search_parameters = parameters
gon.search_query is just what I see in the .rb file, so I guess that means cypher takes that and takes the parameters and then creates the query. Can I get to the string version of the query that must be created by using the parameter values?
The reason I want this is so that I can paste it into the neo4j web admin console tool and tweak it.
Thanks!
Perhaps the simplest way to accomplish that is to write your own print method that given the query and the parameters would print the expanded query. And you can call it before / after the $neo.execute_query

URL length limit for google reader api

I am using "/reader/api/0/stream/items/ids" API to get the item ids for sources that I want.
I have quite a number of sources, so I repeated "s=" parameter to include in the api url.
However, google has given me an error of "URL is too long".
So the question is that How can I solve it so that I just use one time api call to get item ids for that many sources?
Thanks
It seems that /reader/api/0/stream/items/ids path supports a POST method. This means the amount of data you could pass by using POST verb is much more than by using a query string and a GET method.
So use https://www.google.com/reader/api/0/stream/items/ids URL for the post, and pass your query string as a post data. Don't forget to include an action token(T) which is required for POST requests.

Resources