Last active
June 26, 2016 01:35
-
-
Save mydoghasworms/2232055307715178e89e to your computer and use it in GitHub Desktop.
Sample Elasticsearch responses and parsing in ABAP - code to accompany http://ceronio.net/2015/03/yet-another-abap-json-parser-and-some-other-stuff/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"took" : 5, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1000, | |
"max_score" : 1.0, | |
"hits" : [ { | |
"_index" : "bank", | |
"_type" : "account", | |
"_id" : "4", | |
"_score" : 1.0, | |
"_source":{"account_number":4,"balance":27658,"firstname":"Rodriquez","lastname":"Flores","age":31,"gender":"F","address":"986 Wyckoff Avenue","employer":"Tourmania","email":"[email protected]","city":"Eastvale","state":"HI"} | |
} ] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Elasticsearch search response definition | |
data: begin of hit, | |
_index type string, | |
_type type string, | |
_id type string, | |
_score type p decimals 2, | |
_source type ref to json_value, "object, | |
end of hit. | |
data: begin of search_response, | |
took type i, | |
timed_out type string, | |
begin of _shards, | |
total type i, | |
successful type i, | |
failed type i, | |
end of _shards, | |
begin of hits, | |
total type i, | |
max_score type p decimals 2, | |
hits like table of hit, | |
end of hits, | |
end of search_response. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
call method jdoc->map_data | |
exporting | |
json_value = hit-_source | |
changing | |
data = account. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Shows you how to use the JSON parser/mapper located at https://gist.github.com/mydoghasworms/4888a832e28491c3fe47 | |
try. | |
* Parse JSON string into an objectified document in memory | |
jdoc = json_document=>parse( json ). | |
* Map parsed document to a predefined ABAP structure | |
call method jdoc->map_root | |
changing | |
data = search_response. | |
* Map a substructure contained in the mapped data to some different data | |
loop at search_response-hits-hits into hit. | |
call method jdoc->map_data | |
exporting | |
json_value = hit-_source | |
changing | |
data = account. | |
append account to accounts. | |
endloop. | |
catch json_error into lx_jerr. | |
* You're on your own here ... | |
catch cx_root. | |
* ... and here | |
endtry. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
My es return looks like this..
{
"took": 31,
"errors": false,
"items": [{
"index": {
"_index": "orders",
"_type": "order_item_manuscript",
"_id": "161001030000000000000000000002",
"_version": 4,
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"status": 200
}
}
}]
}
My ABAP structures look like this
DATA: BEGIN OF index ,
_index TYPE STRING,
_type TYPE STRING,
_id TYPE STRING,
_version type i,
begin of _shards,
total type i,
successful type i,
failed type i,
end of _shards,
status TYPE i,
END OF INDEX.
data: begin of es_return,
took type i,
errors type string,
begin of items,
index LIKE TABLE OF index,
end of items,
end of es_return.
I only capture took and errors when converting json to es_return but not items...any ideas what could be wrong?