Giter Club home page Giter Club logo

Comments (16)

gauthierm avatar gauthierm commented on June 27, 2024 1

I get the -999 error as well using the URLSessionAdaptorConfiguration and an elasticsearch URL using https. IT works with the NIO example. My URL and certificate are also valid. It seems like maybe the URLSession adapter is not using any of the default certificate validation.

from elasticswift.

prafsoni avatar prafsoni commented on June 27, 2024

@stomper3579 I believe you are talking about this
let match = try QueryBuilders.matchQuery().match(field: "myField", value: "MySearchValue").build()

QueryBuilders and Quries are part of ElasticSwiftQueryDSL
Did you tried
import ElasticSwiftQueryDSL ?

from elasticswift.

stomper3579 avatar stomper3579 commented on June 27, 2024

I did include that import yes.
It says: Value of type 'MatchQueryBuilder' has no member 'match'

from elasticswift.

prafsoni avatar prafsoni commented on June 27, 2024

@stomper3579 It looks like I missed some of the sections in README while updating it.

Please, refer:

let match = try QueryBuilders.matchQuery().set(field: "msg").set(value: "Message").build()

func test_08_Search() throws {

from elasticswift.

prafsoni avatar prafsoni commented on June 27, 2024

Updated examples in ElasticSwiftExamples to 1.0.0-alpha.10

from elasticswift.

stomper3579 avatar stomper3579 commented on June 27, 2024

Thank you! That compiles without errors now. Unfortunately now I get the error:
Error Domain=NSURLErrorDomain Code=-999 "cancelled"

Here is my function based off of the readme.
I've checked the url and credentials with postman to confirm they are good.

func parse() {
        
        let credentials: ClientCredential = BasicClientCredential(username: ES_USERNAME, password: ES_PASSWORD)
        let settings = Settings(forHost: ES_URL_STRING, withCredentials: credentials, adaptorConfig: URLSessionAdaptorConfiguration.default)
        let client = ElasticClient(settings: settings)
        
        let queryBuilder = QueryBuilders.boolQuery()
        
        do {
            let match = try QueryBuilders.matchQuery().set(field: "last_name").set(value: "m").build()

            queryBuilder.must(query: match)
            let query =  try queryBuilder.build()
            
            let sort =  SortBuilders.fieldSort("last_name")
                .set(order: .asc)
                .build()
            
            let request = try SearchRequestBuilder()
                .set(indices: "leads_primary")
                //.set(types: "lead")
                .set(query: query)
                .set(sort: sort)
                .build()

            client.search(request, completionHandler: handler)
            
        }
        catch {
            print("Unexpected error: \(error).")
        }
    }

    func handler(_ result: Result<SearchResponse<String>, Error>) -> Void {
        switch result {
        case .failure(let error):
            print("Error", error)
        case .success(let response):
            print("Response", response)
        }
    }

from elasticswift.

prafsoni avatar prafsoni commented on June 27, 2024

I will need a few more details about your setup.

  1. What is the target platform?
  2. Using cocopods/spm?
  3. Swift/Xcode version ?

from elasticswift.

stomper3579 avatar stomper3579 commented on June 27, 2024

Xcode 11.2.1 just iPhone
swift 4.2
cocoapods

pod 'ElasticSwift', '~> 1.0.0-alpha.10'
pod 'ElasticSwiftCore', '~> 1.0.0-alpha.10'
pod 'ElasticSwiftQueryDSL', '~> 1.0.0-alpha.10'
pod 'ElasticSwiftCodableUtils', '~> 1.0.0-alpha.10'
pod 'ElasticSwiftNetworking', '~> 1.0.0-alpha.10'

from elasticswift.

stomper3579 avatar stomper3579 commented on June 27, 2024

Not sure where all that strikethrough came from

from elasticswift.

prafsoni avatar prafsoni commented on June 27, 2024

strikethrough lines were because of ~>

from elasticswift.

prafsoni avatar prafsoni commented on June 27, 2024

As of v1.0.0-alpha.6 ElasticSwift requires swift 5.0 and above. Not sure how it's compiling for you maybe Xcode is handling it for you.

Since request execution is completely async and based on the above snippet client is initialized inside parse, the client is deallocated shortly after it goes out of scope. As a result, any pending tasks are cancelled.

I would also recommend looking at example ios app here and thread here

from elasticswift.

stomper3579 avatar stomper3579 commented on June 27, 2024

Thank you for helping me in this. I'm using swift 5.0 and your example helped me clean up my code some. I'm now creating the client in ViewDidLoad.
my new function looks like this:

func parse() {
        
        do {
            let query = try QueryBuilders.matchQuery().set(field: "query").set(value: "mouse").build()
            
            let request = try SearchRequestBuilder()
                .set(indices: "leads_primary")
                .set(size: 5)
                .set(query: query)
                .build()
           
            client.search(request, completionHandler: handler)
            
        }
        catch {
            print("Unexpected error: \(error).")
        }
    }

Unfortunately I'm still getting the 999 error. I've confirmed that I don't need a certificate and again I know that the credentials and URL are good as they've been tested in Postman.
Thanks again, I'd really appreciate it if you have any more suggestions.

from elasticswift.

prafsoni avatar prafsoni commented on June 27, 2024

I don’t see anything wrong with the function as such. If you could provide a example app which reproduces the error in a repo and share link here. I can clone and investigate.

from elasticswift.

prafsoni avatar prafsoni commented on June 27, 2024

afcdad1 Fixed ReadMe and updated examples to alpha.11

from elasticswift.

keithburgoyne avatar keithburgoyne commented on June 27, 2024

Funny, I am also seeing the same thing. Using an https URL with URLSessionAdaptorConfiguration.default. I'm using Xcode 12.5.1, and Swift 5.

from elasticswift.

gauthierm avatar gauthierm commented on June 27, 2024

Ok, after looking more into my issue it appears it's impossible to use HTTPS + URLSession adapter without a custom self-signed certificate. I'll file a separate issue.

from elasticswift.

Related Issues (20)

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.