Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queryItems arg for custom func in ElasticsearchClient #27

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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