ElasticSwift icon indicating copy to clipboard operation
ElasticSwift copied to clipboard

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

Open ChurikiTenna opened this issue 3 years ago • 0 comments

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

ChurikiTenna avatar Feb 14 '22 14:02 ChurikiTenna