samyo
(samyo)
July 10, 2019, 3:27pm
1
Hello folks ,
i have this bellow JSON Data, and i want to write a Query , the Query is ,
(Give me all Entities where the "ai_id" has the Value = 0 ).
the JSON Data ,
{
"_index": "try1",
"_type": "_doc",
"_id": "2",
"_score": 1,
"_source": {
"target": {
"br_id": 0,
"an_id": 0,
"ai_id": 0,
"explanation": [
"element 1",
"element 2"
]
},
"process": {
"an_id": 1311,
"pa_name": "micha"
},
"text": "hello world"
}
},
{
"_index": "try1",
"_type": "_doc",
"_id": "1",
"_score": 1,
"_source": {
"target": {
"br_id": 0,
"an_id": 1,
"ai_id": 1,
"explanation": [
"element 3",
"element 4"
]
},
"process": {
"an_id": 1311,
"pa_name": "luca"
},
"text": "the all People are good"
}
}
]
}
}
I tried something like this , and did not work ,
GET try1\_search
{
"query":{
{ "match_all": { "ai_id": 0}}
}
}
Please any Idea or Suggestion , i will be thankfull.
dadoonet
(David Pilato)
July 10, 2019, 4:13pm
2
Try:
GET try1\_search
{
"query":{
{ "match": { "target.ai_id": 0}}
}
}
samyo
(samyo)
July 11, 2019, 7:49am
3
thx , it worked fine .
Can we write your Query using the RestClient API in low level and Highlevel client, and how ?
thx in advance.
samyo
(samyo)
July 11, 2019, 9:07am
4
I wrote smothing like this , using the RestClient in Low Level Client, and it worked fine as "Match_all" , but the Above Query is not about Match_all,
try {
RestClient restClient = RestClient.builder(
new HttpHost("localhost", 9200, "http")).build();
Response response1 = restClient.performRequest("GET", "/try1/_doc/_search?size=" + 10, Collections.singletonMap("pretty", "true"));
String responseBody = EntityUtils.toString(response1.getEntity());
System.out.println("result is : " + responseBody);
} catch (UnknownHostException ex) {
System.out.println("failure : " + ex.getMessage());
}
Can you please expand my Code , so i can write(translate) the ("match": { "target.ai_id": 0}) , in it .
I will be thankfull.
dadoonet
(David Pilato)
July 12, 2019, 3:08pm
5
Here we go with the RestHighLevelClient.
SearchResponse response = client.search(new SearchRequest("test").source(
new SearchSourceBuilder().query(
QueryBuilders.matchQuery("target.ai_id", 0)
)
), RequestOptions.DEFAULT);
samyo
(samyo)
July 15, 2019, 8:34am
6
thx it worked fine , and i get this good result ,
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index": "try1",
"_type": "_doc",
"_id": "2",
"_score": 1,
"_source": {
"target": {
"br_id": 0,
"an_id": 0,
"ai_id": 0,
"explanation": [
"element 1",
"element 2"
]
},
"process": {
"an_id": 1311,
"pa_name": "micha"
},
"text": "hello world"
}
}
]
Is there any Method so i can just take the Content of the "hits_array"?
i need to get this Result like bellow ,
{
"target": {
"br_id": 0,
"an_id": 0,
"ai_id": 0,
"explanation": [
"element 1",
"element 2"
]
},
"process": {
"an_id": 1311,
"pa_name": "micha"
},
"text": "hello world"
}
dadoonet
(David Pilato)
July 15, 2019, 9:43am
7
You can't get this format exactly I think.
system
(system)
Closed
August 12, 2019, 9:49am
9
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.