At the moment when I index a text, I store the frequency count of each word in a database. This works just fine since all searches are based on whole words and all possible searches are known. But now I want to add the option of a prefix search (search of a part of a word). I can get the results/hits from a prefix search with elasticsearch by using this:
GET /my_index/address/_search
{
"query": {
"prefix": {
"main_text": "word_part"
}
}
}
see: https://www.elastic.co/guide/en/elasticsearch/guide/current/prefix-query.html
This is my current mapping:
{
"my-index":{
"mappings":{
"doc":{
"properties":{
"keycounter":{
"properties":{
"counter": {"type":"integer"},
"keyword":{"type":"keyword"}
}
},
"main_text":{
"type":"text",
"fielddata":true
},
"main_text_keycounter":{
"properties":{
"counter":{
"type":"long"
},
"keyword":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
},
"time_written":{
"type":"date"
},
"translated_text":{
"type":"text",
"fielddata":true
},
}
}
}
}
}
But I don´t want to count the frequency for each result I get since it will cost O(N) for each text. Is there some smart way of storing/getting frequency count from this type of a search using elasticsearch?