0

guys. I've struggled with something really weird. I want to get the result of Elasticsearch query, data(inside source). So this is a part of my code.

SearchResult result = jestClient.execute(search);
    JsonObject json = result.getJsonObject();
    Map<String, String> map = new HashMap<>();


    for (JsonElement jsonElement : json.getAsJsonObject("hits").getAsJsonArray("hits")) {
        JsonObject _source = jsonElement.getAsJsonObject().get("_source").getAsJsonObject();
        String orderNumber = _source.get("orderNumber").toString();
        String equipmentCode = _source.get("equipmentCode").toString();
        map.put(orderNumber, equipmentCode);
    }

The thing is the value of orderNumber is "ABCDE". What I expected is ABCDE. (To make it clear, both String contain the double quotes with the value... The funny thing is shown in the debug mode.

I've just checked the values in _source, it has the first value of String "A" still... but the first value of orderNumber is """ and the second value is "A"... I don't know how to resolve this and anyone helping me?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
sunsets
  • 401
  • 5
  • 23

1 Answers1

1

I'm answering for myself and ppl who will have the same problem. I should have used getAsString() instead of toString()... hope that I saved your time

sunsets
  • 401
  • 5
  • 23