I am saving multiple file data to Elasticsearch using /cairn/_doc/id where id is unique id of file. The sample data is like below.
var file = 1;
var meraData = '{"data":[{"page":"1","lineid":"00f6","text":"OIL AND NATURAL ","fileId":"175"},{"page":"1","lineid":"4411","text":"Source Rock Geochemistry","fileId":"175"},{"page":"1","lineid":"c267","text":"CHENNAI -600034","fileId":"175"}]}';
function sendElastic(meraData, file){
$.ajax({
type:'POST',
url: 'https://search-cairn-o3fpbj34hxgttac6b3dnuc37ie.us-east-1.es.amazonaws.com/cairn/_doc/'+file,
data:JSON.stringify(meraData),
contentType: "application/json",
dataType: "json",
success:function(data){
console.log(data);
},
error: function(data){
console.log(data.responseJSON);
}
});
}
After making a GET request to cairn/_search?q=OIL
reponse is like below.
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.57148063,
"hits": [
{
"_index": "cairn",
"_type": "_doc",
"_id": "1",
"_score": 0.57148063,
"_source": {
"data": [
{
"page": "1",
"lineid": "00f6",
"text": "OIL AND NATURAL ",
"fileId": "175"
},
{
"page": "1",
"lineid": "4411",
"text": "Source Rock Geochemistry",
"fileId": "175"
},
{
"page": "1",
"lineid": "c267",
"text": "CHENNAI -600034",
"fileId": "175"
}
]
}
}
]
}
}
How can I change the response format to show only exact matched array value in _source.data array? For example, for query "OIL"
{
"page": "1",
"lineid": "00f6",
"text": "OIL AND NATURAL ",
"fileId": "175"
}
should return in _source.data
Or is it possible to save it like /cairn/_doc/id/lineid ?
inner_hits)