I am unable to create a custom mapping for "hashtags," which is a subfield of "twitter_entities" in elasticsearch. I tried to do it in the following ways:
{
"mappings": {
"tweet" : {
"properties": {
"twitter_entities.hashtags" : {
"type" : "multi_field",
"fields" : {
"hashtag" : {
"type" : "string",
"analyzer" : "hashtag"
},
"autocomplete" : {
"type" : "string",
"index_analyzer" : "hashtag_autocomplete",
"search_analyzer" : "hashtag"
}
}
}
}
}
}
}
This creates another root field called "twitter_entities.hashtags"
{
"mappings": {
"tweet" : {
"properties": {
"hashtags" : {
"type" : "multi_field",
"fields" : {
"hashtag" : {
"type" : "string",
"analyzer" : "hashtag"
},
"autocomplete" : {
"type" : "string",
"index_analyzer" : "hashtag_autocomplete",
"search_analyzer" : "hashtag"
}
}
}
}
}
}
}
and
{
"mappings": {
"tweet" : {
"properties": {
"_parent" : {"type" : "twitter_entities" },
"hashtags" : {
"type" : "multi_field",
"fields" : {
"hashtag" : {
"type" : "string",
"analyzer" : "hashtag"
},
"autocomplete" : {
"type" : "string",
"index_analyzer" : "hashtag_autocomplete",
"search_analyzer" : "hashtag"
}
}
}
}
}
}
}
both just create another root field called "hashtags".
I am unable to find any documentation in the elasticsearch api or forums about doing this. Could anyone point me in the right direction?
Have a look at the documentation for mapping, especially the page about the object type.
You just have to define twitter_entities
as an object and declare its fields under properties
, same as you did for the root object (twitter_entities
). You can omit the type object
since any field that contains other fields under properties
is detected as object anyway.
{
"mappings": {
"tweet" : {
"properties": {
"twitter_entities" : {
"type": "object",
"properties" : {
"hashtag" : {
"type" : "multi_field",
"fields" : {
"hashtag" : {
"type" : "string",
"analyzer" : "hashtag"
},
"autocomplete" : {
"type" : "string",
"index_analyzer" : "hashtag_autocomplete",
"search_analyzer" : "hashtag"
}
}
}
}
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With