0

I have some products that I want to index in an elasticsearch system. One of the field describing these products is the colour. For instance:

  • Red
  • Blue
  • ...

Some of my products can have two or more colours.

Later on, I want to use facets (aggregation) on this field. And, if I understood correctly, you need to base facets on the type "keyword". So I was hoping to do something like that:

PUT products/product/1
{
  "name": "Trousers",
  "colour": "blue, brown",
}

But, as far as I can tell, what I'm doing here is creating a new keyword "blue, brown" instead of attaching two keywords to my product.

So, how do you input several keywords into one keyword field? Or should I use another approach?

Legisey
  • 503
  • 1
  • 4
  • 18

1 Answers1

1

Q: So, how do you input several keywords into one keyword field?

A: I would store the values in an array that is of type keyword.

You would index your documents like so:

PUT products/product/1
{
  "name": "Trousers",
  "colour": ["blue", "brown"]
}
Community
  • 1
  • 1
apt-get_install_skill
  • 2,818
  • 10
  • 27