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

Hi, I am trying to send query with Swift, but it returns error below.

Routing Error. The path you have requested is invalid.

My code is below
(Using ElasticSwift)


           let host = "myEndPoint"
        
        let cred = BasicClientCredential(username: "elastic", password: "myPasswordHere")
        let settings = Settings(forHost: host, withCredentials: cred,
                                adaptorConfig: URLSessionAdaptorConfiguration.default)
        client = ElasticClient(settings: settings)

            let queryBuilder = QueryBuilders.boolQuery()
            let match = try QueryBuilders.matchQuery()
                    .set(field: "name")
                    .set(value: "")
                    .build()
            queryBuilder.must(query: match)

            let query = try queryBuilder.build()

            let request = try SearchRequestBuilder()
                    .set(indices: "my-index-000001")
                    .set(query: query)
                    .build()

            client.search(request, completionHandler: handler)

I've changed parameters, password, username... but nothing seems to be working...

Thank you in advance for your support.

Hey,

are you able to share the full HTTP request and response from Elasticsearch in order to debug this further?

Thanks!

--Alex

Hi, Alex!

Thank you for a response!
Here is the full response from Elasticsearch.

success(ElasticSwiftCore.HTTPResponse(request: ElasticSwiftCore.HTTPRequest(version: HTTP/1.1, method: NIOHTTP1.HTTPMethod.POST, headers: [("Accept", "application/json"), ("Content-Type", "application/json; charset=utf-8"), ("Authorization", "Basic ZWxhc3RpYzo4OTdaejdCeDBKVDRlZHZPOHFTWlZQTGs=")], body: Optional(61 bytes), path: "my-index-000001/_search", queryParams: []), status: NIOHTTP1.HTTPResponseStatus.notFound, headers: [("x-runtime", "0.011705"), ("x-cloud-request-id", "4RAAb5q7RBe87MjkUOJVZw"), ("referrer-policy", "strict-origin-when-cross-origin"), ("x-permitted-cross-domain-policies", "none"), ("x-frame-options", "SAMEORIGIN"), ("x-content-type-options", "nosniff"), ("Content-Length", "66"), ("x-found-handling-instance", "instance-0000000000"), ("x-request-id", "4RAAb5q7RBe87MjkUOJVZw"), ("Content-Type", "application/json;charset=utf-8"), ("Date", "Thu, 24 Feb 2022 00:36:20 GMT"), ("Server", "Jetty(9.4.43.v20210629)"), ("x-xss-protection", "1; mode=block"), ("x-found-handling-cluster", "88a9300b70ec4e009f1795a3b833abf2"), ("x-download-options", "noopen")], body: {"error":"Routing Error. The path you have requested is invalid."}))

I assume that the my-index-000001 index does not exist. Did you create it?

I've created the index following this page before.

I've checked again.

It seems it does exist. Am I missing some steps perhaps?

Is it also readable for the user you tried to connect with?

Not sure.
How do I make it readable?

By setting the correct privileges for the user account you are trying to run the request as.

Alternatively you can try and go with the same user/passwrod that you used to login with Kibana.

Is that here?
I've tried all the privileges, but still not working...

Just to reiterate, you are using the same username/password when logging into Kibana as you are using for your code example?

Running GET my-index-000001/_search works in kibana console?

GET my-index-000001/_search

gave attached result.

I go to Kibana by logging into Elastic with my google account.
(Sorry if that's not what you are asking..)

Which user are you logged in Kibana as (You can check by hovering over the top right icon)? Does that user have the same privileges than the user you are using in your code snippet?

Thank you for the reply!
I am logging in as tenna.churiki@gmail.com.
I was not able to check the privileges for the account, could you tell me where can I check that?


El9NccP2C8gFlZ4bLqbTxI4HJ.jpeg)

I have set a password and tried below.

let cred = BasicClientCredential(username: "tenna.churiki@gmail.com", password: <my password>)

But same result ( Routing Error. The path you have requested is invalid.) returned..

When you are trying to use curl or another command line HTTP client against the endpoint specified in your script,does that work?

I've looked into the http request of script below,

let queryBuilder = QueryBuilders.boolQuery()
            let match = try QueryBuilders.matchQuery()
                    .set(field: "name")
                    .set(value: "")
                    .build()
            queryBuilder.must(query: match)

            let query = try queryBuilder.build()

            let request = try SearchRequestBuilder()
                    .set(indices: "my-index-000001")
                    .set(query: query)
                    .build()

            client.search(request, completionHandler: handler)

The request body was

{"query":{"bool":{"must":[{"match":{"name":{"query":""}}}]}}}

So I entered to curl like below, then it showed successful result.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.