Maps vs Lists in Elasticsearch for optimized query performance

Viewed 42

I have some data I will be putting into Elasticsearch, and want to decide on a format that will optimize query performance. The query will be in words: "Is ID X in category Y?". I have a fixed number of categories (small, say, 5), and possibly a large number of IDs to put into each category (currently in the dozens, but of indeterminate size in the future). Each ID will be in at most one category (possibly none).

Format 1:

{
  "field1": "value1",
  ...
  "categories": {
    "category1": ["id10", "id24", "id38",...],
    ...
    "category5": ["id62", "id19", "id82" ...]
  }
}

or

Format 2:

{
  "field1": "value1",
  ...
  "categories": {
    "id1": "category4",
    "id2": "category2",
    "id3": "category1",
    ...
  }
}

Which data format would be preferred? The latter format has linear lookup time, but possibly many keys.

1 Answers

I think method 1 is better, Id will be more in the future, if you press method 2, then you may need to close the categories index or increase the number of index fields, and using method 1 can be more convenient to determine the type of a single id (indeOf).There are pros and cons. Maybe there's a better way.

Related