3

My co-worker have suggested to use very short names for fields in elastic.

Currently I have mapping like:

"keyword": {
  type: { type: "string" },
  phrase: { type: "string" },
  count: { type: "integer" }
}

but he says it will take to many place, and mapping should be:

"keyword": {
  t: { type: "string" },
  p: { type: "string" },
  c: { type: "integer" }
}

To me it seems strange, to obfuscate the code in this way. Doesnt elasticsearch optimize it?. Could not find help on this in elasticsearch docs resources.

Vitaliy Yanchuk
  • 1,463
  • 1
  • 11
  • 22

2 Answers2

1

I recommend using the longer names for readability. ES is going to do all kinds of magic under the hood to optimize your data and make searches lightning fast, that's why we love it! I recommend not trying to outsmart ES by creating shorter field names that nobody will have any idea what they mean 6 months down the line.

jhilden
  • 12,207
  • 5
  • 53
  • 76
0

That depends what is the goal - to save disk space or speed up queries?

1. Disk costs

Yes, longer field names will create larger indices. ES works differently from RDBMS such as mySQL, where the length of column name does not matter. ES stores field names in the Lucene index and in _source. If disk space is the concern, I would use short-named fields e.g. bn and refer to it via human-friendly constant in the code e.g. Company::BUSINESS_NAME = bn. Short field names may save significant amount of disk space (and also memory, notably when working with large datasets). However it should be considered as per use case - for example sacrificing codebase legibility and maintainability may not be worth saving 2% of disk space.

2. Speed up queries

No, shorter or longer field names will not affect search speed. Search speed is mainly influenced by type mapping, analyzers, normalizers & properly executed queries (e.g. avoid using wildcard star-prefix *name).

Tip: Disk costs may be also reduced by not storing fields with NULL value. See tips here or here.

lubosdz
  • 4,210
  • 2
  • 29
  • 43