Raw JSON Query
Elasticsearch is evolving fast and not all queries and new features which are added to elasticsearch can be immediately added to Elastica. Still it is important that the developers can use all the new functionality. On the one side Elastica tries to map all request with objects which are then mapped to arrays and converted to a JSON string. Because of this it is possible to modify every requets with raw arrays or directly a JSON string from the elasticsearch examples. The basic of all this is the following function.
1
|
|
The function has for params. The first one is the path that should be called, then the type of the Request, the data array which is normally the JSON string and additional query params which should be added to the url. Here is a simple example for a string query in a raw array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
The content of the responseArray will be as following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
To access the total number of hits, the following code is needed:
1
|
|
As it was a “raw” query Elastica didn’t know it was a query. That is also the reason the basic response object was returned instead of a ResultsSet. This array mapping can be used for every single elasticsearch request.