Skip to content

Commit

Permalink
Merge pull request #27 from leonidas-o/main
Browse files Browse the repository at this point in the history
queryItems arg for custom func in ElasticsearchClient
  • Loading branch information
0xTim authored Jun 11, 2024
2 parents ed44995 + 7ce088f commit 0963ff3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ extension ElasticsearchClient {
}
}

public func custom(_ path: String, method: HTTPMethod, body: Data) -> EventLoopFuture<Data> {
public func custom(_ path: String, queryItems: [URLQueryItem] = [], method: HTTPMethod, body: Data) -> EventLoopFuture<Data> {
do {
let url = try buildURL(path: path)
let url = try buildURL(path: path, queryItems: queryItems)
let body = ByteBuffer(data: body)
var headers = HTTPHeaders()
headers.add(name: "content-type", value: "application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,36 @@ class ElasticSearchIntegrationTests: XCTestCase {
XCTAssertEqual(count["value"] as! Double, 50.5)
}

func testCustomRequestWithQueryItems() throws {
// create index
let mappings: [String: Any] = [
"properties": [
"keyword_field": [
"type": "keyword",
"fields": [
"test": [
"type": "text"
]
]
]
]
]
let settings: [String: Any] = ["number_of_shards": 3]
let createResponse = try client.createIndex(indexName, mappings: mappings, settings: settings).wait()
XCTAssertEqual(createResponse.acknowledged, true)

// get indices in json format
struct ESGetSingleIndexResponse: Decodable {
let index: String
}
let resultData = try client.custom("/_cat/indices", queryItems: [URLQueryItem(name: "format", value: "json")], method: .GET, body: "".data(using: .utf8)!).wait()
let results = try JSONDecoder().decode([ESGetSingleIndexResponse].self, from: resultData)
XCTAssertNotNil(results.map { $0.index }.first { $0 == indexName })

// delete index
let deleteResponse = try client.deleteIndex(self.indexName).wait()
XCTAssertEqual(deleteResponse.acknowledged, true)
}

func testCustomSearchWithDataQuery() throws {
for index in 1...100 {
Expand Down

0 comments on commit 0963ff3

Please sign in to comment.