Newbie question on how to structure elasticsearch index

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:

  1. Autocomplete tags based on popularity as the user enters them (like stackoverflow does...)
  2. User search based on popularity
  3. 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!

There is nothing like popularity OOTB in elasticsearch. So you need to implement that manually by yourself.
Elasticsearch is not aware of the queries that have been ran previously or what the users clicked on (aka popularity).

If you use https://www.elastic.co/solutions/app-search, then all that is implemented IIRC. Otherwise, you need to implement that by yourself.

Well I use "popularity", but I really mean "count"... Say that I have 2 posts; both of them have the tag "elastic" and one of them has a tag "elasticsearch", when I search for "ela" I would like the "elastic" tag to show up first indicating that it has 2 occurrences, and then "elasticsearch" would come second with its one occurrence.

How could I get this result efficiently? Thanks!

Looks like a terms aggregation.
Did you look at this?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.