Help with creating mapping for my products


(Radu Gurita) #1

I have this product JSON document that I generate from my database.

{
"product": {
"name": "My product",
"description" : "My product description",
"variations": [
{
"sku": "BLARED10",
"price": 10.15,
"attributes" : {
"colour": "red",
"size": 10,
"material": "leather",
"fastening": "lace"
}
},
{
"sku": "BLABLUE11",
"price": 10.15,
"attributes" : {
"colour": "blue",
"size": 11,
"material": "leather",
"fastening": "slip",
"onSale": 1
}
}
]
}
}

I am currently using this mapping for indexing it in elastic-search:
{
"product": {
"properties": {
"name": {"type": "string"},
"description": {"type": "string"},
"variations": {
"type": "nested",
"properties": {
"sku": {"type": "string"},
"price": {"type": "float"},
"attributes" : {
"type": "object"
}
}
}
}
}
}

Is this the correct way to map it, and if yes, how can I query for example
all the products that have at least one variation with price 10.15 and
colour blue?

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/92728333-eed8-4d35-85b0-bd5427885f9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Ivan Brusic) #2

With inner dccuments, you cannot query two different attributes for the
same inner object. Internally, Elasticsearch/Lucene will flatten all the
inner properties into one array. You would need to switch to nested
documents or even parent/child documents in order to query on a single
deeper document. Searching the mailing list/web will find lots of examples.
Here are a couple:


http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/

Cheers,

Ivan

On Fri, Aug 1, 2014 at 2:14 AM, Radu Gurita gurita.radu@gmail.com wrote:

I have this product JSON document that I generate from my database.

{
"product": {
"name": "My product",
"description" : "My product description",
"variations": [
{
"sku": "BLARED10",
"price": 10.15,
"attributes" : {
"colour": "red",
"size": 10,
"material": "leather",
"fastening": "lace"
}
},
{
"sku": "BLABLUE11",
"price": 10.15,
"attributes" : {
"colour": "blue",
"size": 11,
"material": "leather",
"fastening": "slip",
"onSale": 1
}
}
]
}
}

I am currently using this mapping for indexing it in elastic-search:
{
"product": {
"properties": {
"name": {"type": "string"},
"description": {"type": "string"},
"variations": {
"type": "nested",
"properties": {
"sku": {"type": "string"},
"price": {"type": "float"},
"attributes" : {
"type": "object"
}
}
}
}
}
}

Is this the correct way to map it, and if yes, how can I query for example
all the products that have at least one variation with price 10.15 and
colour blue?

Thanks!

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/92728333-eed8-4d35-85b0-bd5427885f9e%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/92728333-eed8-4d35-85b0-bd5427885f9e%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQAT0CBcnqi00qttGTNmqsunnaMr8wZJA7DL8LPe3diCeA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(system) #3