@@ -16,6 +16,9 @@ public function map(
1616 } elseif (isset ($ elasticSearchResponse ['hits ' ])) {
1717 $ result = $ this ->mapSearchResults ($ elasticSearchResponse );
1818
19+ } elseif (isset ($ elasticSearchResponse ['items ' ])) {
20+ $ result = $ this ->mapBulkActions ($ elasticSearchResponse );
21+
1922 } else {
2023 throw new \Spameri \ElasticQuery \Exception \ResponseCouldNotBeMapped ($ elasticSearchResponse );
2124 }
@@ -35,6 +38,17 @@ public function mapSingleResult(
3538 }
3639
3740
41+ public function mapBulkResult (
42+ array $ elasticSearchResponse
43+ ) : ResultBulk
44+ {
45+ return new ResultBulk (
46+ $ this ->mapStats ($ elasticSearchResponse ),
47+ $ this ->mapBulkActions ($ elasticSearchResponse ['items ' ])
48+ );
49+ }
50+
51+
3852 public function mapSearchResults (
3953 array $ elasticSearchResponse
4054 ) : ResultSearch
@@ -74,7 +88,43 @@ private function mapHit(
7488 $ hit ['_index ' ],
7589 $ hit ['_type ' ],
7690 $ hit ['_id ' ],
77- $ hit ['_score ' ] ?? 1
91+ $ hit ['_score ' ] ?? 1 ,
92+ $ hit ['version ' ] ?? 0
93+ );
94+ }
95+
96+
97+ public function mapBulkActions (
98+ array $ elasticSearchResponse
99+ ) : \Spameri \ElasticQuery \Response \Result \BulkActionCollection
100+ {
101+ $ bulkActions = [];
102+ foreach ($ elasticSearchResponse as $ actionType => $ action ) {
103+ $ bulkActions [] = $ this ->mapBulkAction ($ action , $ actionType );
104+ }
105+
106+ return new \Spameri \ElasticQuery \Response \Result \BulkActionCollection (
107+ ... $ bulkActions
108+ );
109+ }
110+
111+
112+ public function mapBulkAction (
113+ array $ bulkAction ,
114+ string $ actionType
115+ ) : \Spameri \ElasticQuery \Response \Result \BulkAction
116+ {
117+ return new \Spameri \ElasticQuery \Response \Result \BulkAction (
118+ $ actionType ,
119+ $ bulkAction ['_index ' ],
120+ $ bulkAction ['_type ' ],
121+ $ bulkAction ['_id ' ],
122+ $ bulkAction ['_version ' ],
123+ $ bulkAction ['result ' ],
124+ $ this ->mapShards ($ bulkAction ),
125+ $ bulkAction ['status ' ],
126+ $ bulkAction ['_seq_no ' ],
127+ $ bulkAction ['_primary_term ' ]
78128 );
79129 }
80130
0 commit comments