pksprojects / elasticswift Goto Github PK
View Code? Open in Web Editor NEWElasticsearch client in swift
License: MIT License
Elasticsearch client in swift
License: MIT License
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/span-queries.html#span-queries
Add support for span queries:
span_term
queryspan_multi
queryspan_first
queryspan_near
queryspan_or
queryspan_not
queryspan_containing
queryspan_within
queryfield_masking_span
queryMost of the enum cases are named in camel case but some are either snake and/or upper cased.
Naming should be consistent across packages. Since majority of them are camel-cased. Using the camel case as standard will be require minimum change.
In the GetIndexRequest method
func responseHandler(_ response: ESResponse) -> Void
deserializing the response in
let decoded: GetIndexResponse? = try Serializers.decode(data: response.data!)
always throw an keyNotFound
exception.
This because it expect to find a GetIndexResponse
object in the JSON result with following attributes:
instead ElasticSearch JSON wraps this object inside an attribute with the name of the index retrieved.
Expected JSON:
{"aliases":{},"mappings":{},"settings":{"index":{"creation_date":"1559206573432","number_of_shards":"1","number_of_replicas":"1","uuid":"I6Ep6P6FQI2wplQCckfr6Q","version":{"created":"7000199"},"provided_name":"test"}}}
Actual JSON:
{"test":
{"aliases":{},"mappings":{},"settings":{"index":{"creation_date":"1559206573432","number_of_shards":"1","number_of_replicas":"1","uuid":"I6Ep6P6FQI2wplQCckfr6Q","version":{"created":"7000199"},"provided_name":"test"}}}
}
SInce AsyncHTTPClient 1.0 is released it's better to adapt to AsyncHTTPClient as the underlying Http client as it provides richer features expected by an Http client.
Project currently lacks official contribution guidelines. Which is not good for contributors hindering them to create pull request in the desired manner.
Document update api support
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update.html
Are there requirements for this to work beyond what's in the readme? I've tried the code samples you supply but there are numerous errors throughout. Especially in the Search section, .match doesn't exist.
Add support for following queries:-
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/joining-queries.html
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/specialized-queries.html
Add support for Specialized queries
more_like_this
queryscript
querypercolate
querywrapper
queryHi, I am trying to use elastic search.
But getting this error
status: NIOHTTP1.HTTPResponseStatus.notFound
ElasticsearchError(error: "Routing Error. The path you have requested is invalid.", status: nil)
My code is below (pretty much copied from readme).
func makeClient() -> ElasticClient {
let host = "<my endpoint is on here>"
let cred = BasicClientCredential(username: "elastic", password: "<password here>")
let settings = Settings(forHost: host,
withCredentials: cred,
adaptorConfig: URLSessionAdaptorConfiguration.default)
return ElasticClient(settings: settings)
}
func searchRequest() {
func handler(_ result: Result<SearchResponse<Sauna>, Error>) -> Void {
switch result {
case .failure(let error):
print("searchRequest.Error", error) // getting error here
case .success(let response):
print("searchRequest.Response", response)
}
}
client = makeClient()
do {
let queryBuilder = QueryBuilders.boolQuery()
let match = try QueryBuilders.matchQuery()
.set(field: "saunas")
.set(value: "Sauna")
.build()
queryBuilder.must(query: match)
let query = try queryBuilder.build()
let sort = SortBuilders.fieldSort("saunas")
.set(order: .asc)
.build()
let request = try SearchRequestBuilder()
.set(indices: "indexName")
.set(types: "type")
.set(query: query)
.add(sort: sort)
.build()
client.search(request, completionHandler: handler)
} catch {
print("searchRequest.error", error)
}
}
I have Engines named "saunas" on elastic which contains 89 documents.
I have no idea what "indices" or "types" means in the SearchRequestBuilder.
Is there any documents that explaining those basic things?
I am pretty new to elastic, so sorry for the noob questions.. but I've been struggling for weeks.
Really appreciate your help!!!
Since, Query, ScoreFunction, and Sort conform to Codable Protocol the toDic() which was primarily introduced to ease serialization of class/struct with JSONSerialization in pre-Codable.
It will be good time to remove toDic() before beta/1.0.0
As per official documentation:
https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html#_what_are_mapping_types
ElasticSwift is not aligned with above deprecation and some operations still use mapping type.
Es. Index and Search
The following features are missing from the search request.
track_scores
supportsindices_boost
matched_queries
in response. However, Setting _name
for query is a change in supported Queries)https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-body.html
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/geo-queries.html
geo_shape
geo_bounding_box
geo_distance
geo_polygon
I see you are experimenting new libraries.
I kindly ask you to keep compatibility with at least the latest 3 iOS versions (at the moment 10 11 12)
Another recommendation is to avoid 3rd party libraries as much as possible, i.e. avoid Alamofire or other networking libs that are not maintained by Apple if they don't generate really great huge benefits, it would be a pain to maintain on OS upgrade.
Thanks for the great work you are doing!
Since aplha.8
SearchResponse
was returning hits
are an empty array. This is due to refactoring SearchHit
to make all members constants.
In the unit tests, the tests results are not asserted.
My elastic instance is not running on localhost, so each API invocation fails but tests are reported as ended successfully.
Thanks for your response!
Add support for _rank_eval
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-rank-eval.html
The response of GetIndexRequest returns a wrong data type for Index settings field creation_date and the deserialization fails.
{ "settings": { "index": {
"creation_date": "1563813426580",
"number_of_shards": "1", "number_of_replicas": "1", "uuid": "N-yD3XmlQd28E9iR4iIliA", "version": { "created": "7000199" },
It's really weird but Elastic returns creation_date as String containing a date in epoch format (seconds from 1970).
Add support for _field_caps
.
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-field-caps.html#search-field-caps
This would be similar to how Fluent works in Vapor and avoid callbacks.
I could see something along these lines:
return client.query().set(indices: ...).set(types: ...).search().map {
// Code
}
Where .search()
returns an EventLoopFuture<SearchResponse<T: Codable>>
It would make the code much more concise (Swifty 😉) and would fit better with packages like Vapor and Soto.
Currently, QueryBuilder has a query
property that returns build query. This should really be a build()
. Don't remember why it was implemented this way, this needs to be corrected.
Add support for suggesters
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-suggesters.html
Describe the bug
On iOS (and possibly macOS) The custom self-signed TLS certificate support doesn't let you use a valid public certificate from—for example—Let's Encrypt.
To Reproduce
Trying to use the example from the documentation to make a basic query on a server that is using a valid public TLS certificate on iOS:
import ElasticSwift
import ElasticSwiftNetworking
var settings = Settings(forHost: "https://www.example.com", adaptorConfig: URLSessionAdaptorConfiguration.default) // Creates default settings for client
var client = ElasticClient(settings: settings) // Creates client with specified settings
This causes a relatively opaque error message:
Error Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://www.example.com/my-index/_search?, NSErrorFailingURLKey=https://www.example.com/my-index/_search?, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <CD9D4F4D-A6F9-4BA9-8B29-E75A486DFA3E>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <CD9D4F4D-A6F9-4BA9-8B29-E75A486DFA3E>.<1>, NSLocalizedDescription=cancelled}
Expected behavior
I expect that supporting a self-signed certificate requires configuration but supporting a public trusted certificate works by default. The NIO adapter seems to work by default.
Environment Details (please complete the following information):
ElasticSwift (please complete the following information):
Additional context
It looks to me like the code in https://github.com/pksprojects/ElasticSwift/blob/master/Sources/ElasticSwiftNetworking/SessionManager.swift#L94-L96 is what causes the -999 error to occur. I'm not familiar enough with custom TLS handling in URLSession to be able to say for sure, but should this call the completion handler with .performDefaultHandling
instead of .cancelAuthenticationChallenge
?
Currently, lib can be visualized into different conceptual modules. It is a good idea to split lib into smaller modules. This will allow managing lib and dependencies in a cleaner way.
Code Coverage needs to be > 70% before beta
Add support for _search/template
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-template.html
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.