Skip to content

Commit fa75715

Browse files
committed
add support for ES8
1 parent e36b440 commit fa75715

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/elastic.atd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type multiget = {
2929

3030
type id_hit = {
3131
index <json name="_index"> : string;
32-
doc_type <json name="_type"> : string;
32+
?doc_type <json name="_type"> : string option;
3333
id <json name="_id"> : string;
3434
}
3535

src/es.ml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ let fail_lwt fmt =
7070
Lwt.fail ErrorExit
7171
end fmt
7272

73+
let default_doc_type = "_doc"
74+
7375
type 't json_reader = J.lexer_state -> Lexing.lexbuf -> 't
7476

7577
type 't json_writer = Bi_outbuf.t -> 't -> unit
@@ -91,8 +93,8 @@ let es6_config = {
9193
let es7_config = {
9294
read_total = Elastic_j.read_total;
9395
write_total = Elastic_j.write_total;
94-
default_get_doc_type = "_doc";
95-
default_put_doc_type = Some "_doc";
96+
default_get_doc_type = default_doc_type;
97+
default_put_doc_type = Some default_doc_type;
9698
}
9799

98100
let rec coalesce = function Some _ as hd :: _ -> hd | None :: tl -> coalesce tl | [] -> None
@@ -106,14 +108,15 @@ let get_es_version { verbose; _ } host =
106108
| "5" :: _ -> Lwt.return `ES5
107109
| "6" :: _ -> Lwt.return `ES6
108110
| "7" :: _ -> Lwt.return `ES7
111+
| "8" :: _ -> Lwt.return `ES8
109112
| other :: _ ->
110113
match int_of_string other with
111114
| exception exn -> Exn_lwt.fail ~exn "invalid ES version number : %s" number
112115
| _ -> Exn_lwt.fail "unsupported ES version number : %s" number
113116

114117
let get_es_version_config' = function
115118
| `ES5 | `ES6 -> es6_config
116-
| `ES7 -> es7_config
119+
| `ES7 | `ES8 -> es7_config
117120

118121
let get_es_version_config common_args host es_version { Config_t.version = config_version; _ } cluster_version =
119122
let version = coalesce [ es_version; cluster_version; config_version; ] in
@@ -183,9 +186,10 @@ let string_of_hit_format = function
183186

184187
let map_of_hit_format =
185188
let open Elastic_t in function
186-
| `FullID -> (fun ({ index; doc_type; id; _ } : 'a Elastic_t.option_hit) -> sprintf "/%s/%s/%s" index doc_type id)
189+
| `FullID -> (fun ({ index; doc_type; id; _ } : 'a Elastic_t.option_hit) ->
190+
sprintf "/%s/%s/%s" index (Option.default default_doc_type doc_type) id)
187191
| `ID -> (fun hit -> hit.id)
188-
| `Type -> (fun hit -> hit.doc_type)
192+
| `Type -> (fun hit -> Option.default default_doc_type hit.doc_type)
189193
| `Index -> (fun hit -> hit.index)
190194
| `Routing -> (fun hit -> Option.default "" hit.routing)
191195
| `Hit -> (fun hit -> Elastic_j.string_of_option_hit J.write_json hit)
@@ -1544,6 +1548,7 @@ let common_args =
15441548
Some `ES5, Arg.info [ "5"; ] ~docs ~doc:"force ES version 5.x";
15451549
Some `ES6, Arg.info [ "6"; ] ~docs ~doc:"force ES version 6.x";
15461550
Some `ES7, Arg.info [ "7"; ] ~docs ~doc:"force ES version 7.x";
1551+
Some `ES8, Arg.info [ "8"; ] ~docs ~doc:"force ES version 8.x";
15471552
])
15481553
in
15491554
let verbose =

src/wrap.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Version = struct
99
| `ES5
1010
| `ES6
1111
| `ES7
12+
| `ES8
1213
]
1314

1415
type t = [
@@ -21,12 +22,14 @@ module Version = struct
2122
| `Int 5 | `String "5" | `Intlit "5" -> `ES5
2223
| `Int 6 | `String "6" | `Intlit "6" -> `ES6
2324
| `Int 7 | `String "7" | `Intlit "7" -> `ES7
25+
| `Int 8 | `String "8" | `Intlit "8" -> `ES8
2426
| x -> Exn.fail "unknown ES version %s" (J.to_string x)
2527

2628
let unwrap = function
2729
| `Auto -> `String "auto"
2830
| `ES5 -> `Int 5
2931
| `ES6 -> `Int 6
3032
| `ES7 -> `Int 7
33+
| `ES8 -> `Int 8
3134

3235
end

0 commit comments

Comments
 (0)