Hi, I'm trying to replace mysql fulltext search with elasticsearch in my application, but I'm not sure how to optimally design my data structure(s) and perform the searches. Right now, all of my data is in a single elasticsearch index, like this example:
{
"_index": "posts",
"_type": "post",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"@version": "1",
"title": "The post title",
"description": "The post description",
"tags": ["foo", "bar"],
"content": "A long content string",
"user_name": "John",
"user_id": 1,
"post_id": 1,
"@timestamp": "2018-09-17T14:05:51.424Z"
}
}
I didn't specify mappings so far. I'm trying to do 3 searches that were trivial to implement, but inefficient in mysql:
- Autocomplete tags based on popularity as the user enters them (like stackoverflow does...)
- User search based on popularity
- Global post search in the description and content fields
I've looked at the "completion suggester", but it doesn't seem like it can do the "popularity" search.
So, what would be the optimal indexing/search strategy for these requirements? Should I separate the tags and users from the posts? What query would be optimal for this&
Thanks!