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

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

Open
ChurikiTenna opened this issue Feb 14, 2022 · 0 comments

Comments

@ChurikiTenna
Copy link

ChurikiTenna commented Feb 14, 2022

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

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

No branches or pull requests

1 participant