IDs with special characters


(Keith) #1

I'm setting up elasticsearch with my java spring app. When I'm attempting to get records, I'm having an issue with retrieval and it seems to be due to the ID's of my records. For example, here's an Id of a record: "GD+GGAct+-+Avg+FIN201-02-01115ce07a-e5e7-4ba3-9117-4a7a49c3df01". I'm using the RestHighLevelClient.

Using kibana, I can encode and get the record with the Dev Tools. But using the code below, neither the raw id or the encoded Id is working

try {
			GetRequest request = new GetRequest();
			request.index("my-index");
			request.type("record");
			request.id(URLEncoder.encode("GD+GGAct+-+Avg+FIN201-02-01115ce07a-e5e7-4ba3-9117-4a7a49c3df01"));
			GetResponse response = this.restClient.get(request, RequestOptions.DEFAULT);			
			if(response.isExists()) {
				String sourceAsString = response.getSourceAsString();
			}else {
				logger.info("response does not exists");				
			}
		}catch(IOException e) {
			logger.info("error...");
			logger.info(e.getLocalizedMessage());
		}

any suggestions?


(David Pilato) #2

I just tried that in Kibana:

DELETE test
PUT test/_doc/GD+GGAct+-+Avg+FIN201-02-01115ce07a-e5e7-4ba3-9117-4a7a49c3df01
{
  "foo": "bar"
}
GET test/_doc/GD+GGAct+-+Avg+FIN201-02-01115ce07a-e5e7-4ba3-9117-4a7a49c3df01

This gives:

{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "GD GGAct - Avg FIN201-02-01115ce07a-e5e7-4ba3-9117-4a7a49c3df01",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "foo" : "bar"
  }
}

Then this code in Java:

        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(HttpHost.create("http://localhost:9200")));

        GetResponse getResponse = client.get(new GetRequest("test", "_doc", "GD+GGAct+-+Avg+FIN201-02-01115ce07a-e5e7-4ba3-9117" +
                "-4a7a49c3df01"), RequestOptions.DEFAULT);

        System.out.println("getResponse = " + getResponse);

        client.close();

It gives:

getResponse = {"_index":"test","_type":"_doc","_id":"GD GGAct - Avg FIN201-02-01115ce07a-e5e7-4ba3-9117-4a7a49c3df01","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source":{"foo":"bar"}}

(system) closed #3

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