Giter Club home page Giter Club logo

elasticswift's Issues

Inconsistency in Enum case naming

Most 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.

GetIndexRequest - API result is not parsed properly

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:

  • aliases
  • mappings
  • settings

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"}}}
}

Add Contribution Guidelines

Project currently lacks official contribution guidelines. Which is not good for contributors hindering them to create pull request in the desired manner.

Readme examples and ExampleRepo are not updated

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.

ElasticsearchError(error: "Routing Error. The path you have requested is invalid.", status: nil)

Hi, 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!!!

Remove no longer necessary toDic() method

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

Add missing features for SearchRequest

The following features are missing from the search request.

  • Support for multiple Sort
  • Source filtering
  • Stored Fields
  • Scripted Fields
  • track_scores supports
  • Doc Value Fields
  • post_filter
  • highlighting
  • Rescoring
  • Search Type
  • Scroll
  • Preference
  • version
  • seq_no_primary_term
  • indices_boost
  • Named Query (Added support to include matched_queries in response. However, Setting _name for query is a change in supported Queries)
  • inner_hits
  • Field collapsing
  • search after

https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-body.html

Please don't raise target platform requirements

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!

SearchResponse broken in alpha.8

Since aplha.8 SearchResponse was returning hits are an empty array. This is due to refactoring SearchHit to make all members constants.

GetIndexResponse IndexSettings creationDate is returned as String (not Date)

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).

Have you considered using Futures instead of callbacks?

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.

Builders should have a build() method

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.

Not possible to use server on HTTPS with a valid public certificate

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):

  • OS: iOS
  • Version iOS 14, Xcode 12

ElasticSwift (please complete the following information):

  • Version 1.0.0-beta.1

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.