Hi everyone,
I have a question about array object in elasticsearch
For example i have a mapping like this one:
PUT test
{
"settings": { ...},
"mappings": {
"properties": {
"id":{
"type": "keyword"
},
"levels":{
"properties": {
"translations":{
"type": "text",
"analyzer": "english"
},
"id":{
"type": "keyword"
}
}
}
}
}
}
And then, i add documents in index test
:
{
"id": 1,
"levels":[
{"id": 1, "translations": "lalaland"},
{"id": 2, "translations": "lili"},
{"id": 3, "translations": "lalaland"}
]
}
Then, i launch some search
GET test/_search
{
"_source": "levels.translations",
"query": {
"match": {
"levels.translations": "lalaland"
}
},
"highlight": {
"fields": {"levels.translations": {}}
}
}
The result is:
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.3955629,
"_source" : {
"levels" : [
{
"id": 1,
"translations" : "lalaland"
},
{
"id": 2,
"translations" : "lili"
},
{
"id": 3,
"translations" : "lalaland"
}
]
},
"highlight" : {
"levels.translations" : [
"<em>lalaland</em>",
"<em>lalaland</em>"
]
}
}
]
Are there anyway to retrieve just the first and the thirst element in levels
field. I wonder if i can do it with nested ?
Thank you all.