Reputation: 788
How to create index for nested data structure with list? There will be list of otherUserID's and I don't know how to index them with elasticsearch 6.5.
UserID -> OtherUserID-> name:"text" , count : "long"
Upvotes: 0
Views: 411
Reputation: 7874
You can uses nested data type for creating such a field and indexing list of object. Refer to the example below and modify it to your needs:
Mapping:
PUT testindex
{
"mappings": {
"_doc": {
"properties": {
"nestedField": {
"type": "nested",
"properties": {
"field1": {
"type": "text",
"fields": {
"keywords": {
"type": "keyword"
}
}
},
"field2": {
"type": "integer"
}
}
}
}
}
}
}
Adding documents:
For single item in list:
PUT testindex/_doc/1
{
"nestedField": [
{
"field1": "Some text",
"field2": 10
}
]
}
For multiple items in list:
PUT testindex/_doc/2
{
"nestedField": [
{
"field1": "Some other text",
"field2": 11
},
{
"field1": "random value",
"field2": 15
}
]
}
Upvotes: 1