Hi all, I'm brand new to ElasticSearch (1.0.0 RC1), superb software with so
many new things to learn and I have been pulling our my hair on this for
many days. I think I'm going bald.
Basically I want to search a list of products each contains many options
which in turn contain many values. I will have the mapping and sample data
posted below:
POST test/product/_mapping
{
"product":{
"properties" : {
"name" : {"type" : "string", "store":"yes"},
"manufacturer": {"type": "string"},
"options" : {
"type": "nested",
"properties": {
"name": {"type": "string"},
"values": {"type": "nested"}
}
},
"price":{"type": "integer"}
}
}
}
POST test/product/1
{
"name": "Shirt 1",
"manufacturer": "Umbro",
"options":[
{
"id": 1,
"name": "Color",
"values" : [
{
"id": 1,
"name": "red"
}
]
},
{
"id": 2,
"name": "Size",
"values" : [
{
"id": 2,
"name": "XL"
},
{
"id": 3,
"name": "S"
},
{
"id": 4,
"name": "M"
}
]
}
],
"price":200000
}
POST test/product/2
{
"name": "Shirt 2",
"manufacturer": "Nike",
"options":[
{
"id": 1,
"name": "Color",
"values" : [
{
"id": 11,
"name": "yellow"
},
{
"id": 1,
"name": "red"
}
]
},
{
"id": 2,
"name": "Size",
"values" : [
{
"id": 2,
"name": "XL"
},
{
"id": 4,
"name": "M"
}
]
}
],
"price":100000
}
And this is my current search query, I'm not even sure if it's efficient,
for now it doesn't return anything tho. I simply want to search all
products with the color red and size m:
POST test/product/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"nested": {
"path": "options",
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"term": {
"options.name": "color"
}
},
{
"nested": {
"path":
"options.values",
"filter": {
"term": {
"options.values.name": "red"
}
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"options.name": "size"
}
},
{
"nested": {
"path":
"options.values",
"filter": {
"term": {
"options.values.name": "m"
}
}
}
}
]
}
}
]
}
}
}
}
]
}
}
}
}
}
It seems like the issue is in the "must" key, but I'm not sure how to fix
it.
Also, I want to get the list of all the available options within the
result as well, how should I do it? (For example, if there were 1000
products, and the result returns 100 products then I want to have the list
of all available options for all these 100 products). It seems like the new
Aggregation on RC1 can help me to do that, I'm just not sure how
--
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/684b86c5-c961-49c0-b5c0-079d01da049c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.