Multiple must tokens on nested object fields


(Frank Hsueh) #1

help! I can't figure out how to apply a must filter on a nested type.

I tried a filter/nested with query/bool/must which doesn't work. anybody
done this kind of thing before ?

mapping

{
"someobject" : {
"properties" : {
"organization" : {
"type" : "nested",
"properties" : {
"filtername" : { "type" : "string", "index" : "not_analyzed" },
"foldername" : { "type" : "string", "index" : "not_analyzed" },
"hidden" : { "type" : "boolean" }
}
},
"otherfields" : {
"type" : "string",
}
}
}
}
<<<<

my best guess is:

{
"filter": {
"nested": {
"path": "organization",
"query": {
"bool": {
"must": [
{ "term": { "organization.hidden": { "value": "false" } } },
{ "term": { "organization.filtername": { "value": "myfilter" }
} },
{ "term": { "organization.foldername": { "value": "myfolder" }
} }
]
}
}
}
}
}
<<<<

--
Frank Hsueh | frank.hsueh@gmail.com


(Frank Hsueh) #2

ha ha ... I woke up this morning and found

http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html

and it works!

On Fri, May 11, 2012 at 10:57 PM, Frank Hsueh frank.hsueh@gmail.com wrote:

help! I can't figure out how to apply a must filter on a nested type.

I tried a filter/nested with query/bool/must which doesn't work. anybody
done this kind of thing before ?

mapping

{
"someobject" : {
"properties" : {
"organization" : {
"type" : "nested",
"properties" : {
"filtername" : { "type" : "string", "index" : "not_analyzed" },
"foldername" : { "type" : "string", "index" : "not_analyzed" },
"hidden" : { "type" : "boolean" }
}
},
"otherfields" : {
"type" : "string",
}
}
}
}
<<<<

my best guess is:

{
"filter": {
"nested": {
"path": "organization",
"query": {
"bool": {
"must": [
{ "term": { "organization.hidden": { "value": "false" } } },
{ "term": { "organization.filtername": { "value": "myfilter" }
} },
{ "term": { "organization.foldername": { "value": "myfolder" }
} }
]
}
}
}
}
}
<<<<

--
Frank Hsueh | frank.hsueh@gmail.com

--
Frank Hsueh | frank.hsueh@gmail.com


(system) #3