How to get particular element by index

Say I have this document stored.

###exemplary data
{"name": "haris","projects": [{"title": "Splunk"},{"title": "QRadar"},{"title": "LogAnalysis"}]}

{"name": "khalid","projects": [{"title": "MS"},{"title": "Google"},{"title": "Apple"}]}

{"name": "Hamid","projects": [{"title": "Toyota"},{"title": "Honda"},{"title": "Kia"}]}

###code for mapping
PUT index_name
{
"mappings": {
"iterations_type": {
"properties": {
"projects": {
"type": "nested",
"include_in_parent": true
}
}
}
}
}

My QUESTION: I want to get 2nd element of "projects" array against some specific name e.g "name": "khalid".

What I tried so far:
I am new to ES and I searched forums for the answer, some suggest to specify mapping of "projects" key. I tried that too and the issue I face is

  1. when I create empty index, specify the mapping first and then insert the data, I get an error like "reason": "object mapping ["projects"] can't be changed from nested to non-nested"
  2. when I create empty index, insert data first and then specify the mapping, I get and error like ""reason": "index [<>] already exists"
    ard for me to specify mapping for each field explicitly

Thanks in advance

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.