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

GetRequest can not get a document when "id" contains a special character #33445

Closed
casper1149 opened this issue Sep 5, 2018 · 3 comments
Closed

Comments

@casper1149
Copy link

Hello,

Elasticsearch version: 6.4.0

JVM version: 1.8.0

OS version: MacOSX 17.6.0 Darwin Kernel

I have an index with the next mapping

{
  "_doc": {
    "properties": {
      "id": {
        "type": "keyword"
      }
    }
  }
}

and next setting

"analysis": {
    "analyzer": {
        "default": {
            "tokenizer": "keyword"
        }
     }
}

I indexed a simple document using the IndexRequest API, where the "id" value contains a special character "+", so the result document looks like this

{
  "_index": "index_v1",
  "_type": "_doc",
  "_id": "my-id.1+8",
  "_source": {
    "id": "my-id.1+8",
  }
}

As expected I am not able to GET this document without encoding the "+" character

GET index_v1/_doc/my-id.1+8

But I am able to GET it using an encoded "+" character

GET index_v1/_doc/my-id.1%2B8

and to make sure I tested it with a simple HTTP GET request

curl http://host:port/index_v1/_doc/my-id.1%2B8

also it is possible to SEARCH for this document using the value as it is, i.e.

GET index_v1/_search
{
  "query": {
    "term": {
      "id": {
        "value": "my-id.1+8"
      }
    }
  }
}

However when I try to use the GetRequest API, the document is not found

GetRequest getRequest = new GetRequest("index_v1").id("my-id.1%2B8").type("_doc");
GetResponse response = client.get(getRequest, RequestOptions.DEFAULT);

If I print the "getRequest" it looks correct

get [index_v1][_doc][my-id.1%2B8]: routing [null]

The "response" also looks correct, however the document was not found

{"_index":"index_v1","_type":"_doc","_id":"my-id.1%2B8","found":false}

So I was expecting to be able to get the same result using the GetRequest API as I am getting when I GET this document manually.

Can you please take a look and explain whether it is a bug or an expected behavior, or may be I am just missing something?

@casper1149
Copy link
Author

I also tried to get the same document using the low level client and it worked

Request request = new Request("GET", "http://host:port/index_v1/_doc/my-id.1%2B8");
Response response = client.getLowLevelClient().performRequest(request);

@jasontedor
Copy link
Member

The REST layer does decoding of + into space and decoding of percent-encoded characters that the transport layer does not. The issue of + being decoded into a space is one fraught with some history. See the discussion on #33164 for some recent history on this. We have a proposal that we modify this behavior in a future release, your feedback there is certainty welcome. Does that help? I think then that we can close this issue? 🤔

@casper1149
Copy link
Author

Thanks for the info, in this case I'll be using the low level client to perform this operation until this gets resolved in the future release

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

2 participants