Hello Experts,
I am a newbie to Elastic Search and I am using elastic search to support my RESTful webservices.
Here is how I am indexing my JSON documents
PUT users/group/1312
{
"userID" : "U1234",
"groupName": "G2",
"groupID" : "1312",
"accounts": [
{
"accountNumber":"8888",
"authorizationLevel":1,
"addressLine1":"898 Street",
"addressLine2":"Apt 102",
"city":"Stamford",
"state":"CT",
"zipcode":"60660",
"userCount":0
},
{
"accountNumber":"8688",
"authorizationLevel":1,
"addressLine1":"500 Street",
"addressLine2":"Apt 1",
"city":"Atlanta",
"state":"GA",
"zipcode":"60660",
"userCount":0
},
{
"accountNumber":"9999",
"authorizationLevel":3,
"addressLine1":"500 Street",
"addressLine2":"Apt 1",
"city":"Charlotte",
"state":"NC",
"zipcode":"60660",
"userCount":0
}
]
}
I am trying to match the user ID value within the type group and fetch the list of documents containing that user ID. I only want to fetch the required fields like groupID, accounts(List).
I used this and played around with a couple of options to get the required fields, but I end up getting the entire document
I tried termquery and also set the fetchsource value to false.
TermQuery didnot return any hits.
SearchResponse searchResp = client.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.QUERY_AND_FETCH)
.setQuery(QueryBuilders.matchQuery("userID", "U1134"))
.execute()
.actionGet();
So when I tried to get the specific field from the map returned by getSource. I am getting parse exceptions while using Jackson to convert the JSON to a Java POJO.
On checking, when I used getSource, it removed all the quotes from the JSON document(compared to getSourceAsString) and I think that's causing issues in parsing.
I don't want to go down the path of traversing the tree structure of Jackson
Please advise if I am missing anything here.
Thanks