Hello Folks,
i have this JSON DATA in Elasticsearch , and i want to get a specific "id" from it using Low Level Rest Clien API in java.
this is the JSON DATA ,
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "try1",
"_type": "_doc",
"_id": "1",
"_score": 1,
"_source": {
"target": {
"id": 2,
"array_id": [
"element 1"
,
"element 2"
]
},
"declaration": {
"nummber_id": 1311,
"name": "lucas",
},
"text": "welcome to the new world"
}
}
]
}
}
i want to get the all Content of this Index at first.
And i want to get after that just ("id": 2) under the target Field.
is that possible in Java Low Level Rest client API ? and how ?
my Output should be like example,
{
"_index": "try1",
"_type": "_doc",
"_id": "1",
"_score": 1,
"_source": {
"target": {
"id": 2,
"array_id": [
"element 1"
,
"element 2"
]
},
"declaration": {
"nummber_id": 1311,
"name": "lucas",
},
"text": "welcome to the new world"
}
}
OR just the "id": 2
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "try1",
"_type": "_doc",
"_id": "1",
"_score": 1,
"_source": {
"target": {
"id": 2
}
}
}
]
}
can i start with somthing like this bellow ? ,
GetResponse response = client.prepareGet("try1", "_doc",
"1").setFields("target", "id")
.execute().actionGet();
The Goal from all this Question is , i do not want to send JSON Data wich have the same "id" inside it into Elasticsearch. is that possible to do using Client API low Level???
Èxample bellow to avoid two "_source" in one Index, wich they have under "target" the same ("id": 2 ), this case i want to avoid , is that possible?
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "try1",
"_type": "_doc",
"_id": "2",
"_score": 1,
"_source": {
"target": {
"id": 2,
"array_id": [
"element 1"
,
"element 2"
]
},
"declaration": {
"nummber_id": 1311,
"name": "lucas"
},
"text": "welcome to the new world"
}
}
,
{
"_index": "try1",
"_type": "_doc",
"_id": "1",
"_score": 1,
"_source": {
"target": {
"id": 2,
"array_id": [
"element 1"
,
"element 2"
]
},
"declaration": {
"nummber_id": 1311,
"name": "lucas",
},
"text": "hallo here is the text"
}
}
]
}
}
thx.