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

Readme examples and ExampleRepo are not updated #79

Closed
stomper3579 opened this issue Mar 25, 2020 · 16 comments
Closed

Readme examples and ExampleRepo are not updated #79

stomper3579 opened this issue Mar 25, 2020 · 16 comments
Assignees
Labels
Milestone

Comments

@stomper3579
Copy link

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.

@prafsoni
Copy link
Contributor

prafsoni commented Mar 25, 2020

@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 ?

@stomper3579
Copy link
Author

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

@prafsoni prafsoni changed the title Readme errors Readme examples are not updated Mar 25, 2020
@prafsoni prafsoni added this to the alpha.11 milestone Mar 25, 2020
@prafsoni prafsoni self-assigned this Mar 25, 2020
@prafsoni prafsoni changed the title Readme examples are not updated Readme examples and ExampleRepo are not updated Mar 25, 2020
@prafsoni
Copy link
Contributor

@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 {

@prafsoni
Copy link
Contributor

Updated examples in ElasticSwiftExamples to 1.0.0-alpha.10

@prafsoni prafsoni added the docs label Mar 26, 2020
@stomper3579
Copy link
Author

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

@prafsoni
Copy link
Contributor

I will need a few more details about your setup.

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

@stomper3579
Copy link
Author

stomper3579 commented Mar 26, 2020

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'

@stomper3579
Copy link
Author

Not sure where all that strikethrough came from

@prafsoni
Copy link
Contributor

strikethrough lines were because of ~>

@prafsoni
Copy link
Contributor

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

@stomper3579
Copy link
Author

stomper3579 commented Mar 27, 2020

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.

@prafsoni
Copy link
Contributor

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.

@prafsoni
Copy link
Contributor

afcdad1 Fixed ReadMe and updated examples to alpha.11

@gauthierm
Copy link

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.

@keithburgoyne
Copy link

keithburgoyne commented Jul 22, 2021

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.

@gauthierm
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants