Search nested "nested objects" using "wildcard paths"

Hi,

I've been try to use Elasticsearch to query heavily nested documents like
below (simplified document). In the document below, I would like to search
for all color values without having to specify a full "path" in nested
queries/filters. More like a wildcard path, for example color.*.value=v2 .
I could also include color types (blue, gray,red, etc) in the inner objects
and remove one level of nesting, but I need the nesting to update
(overwrite) a particular color type array (e.g. all blues). Including this
information in the inner object and decreasing nesting levels will
complicate updates.

If this is not possible, I would greatly appreciate it if I was pointed in
the right direction.
-Ash

{
"color": {
"blue": [
{
"name": "n3",
"value": "v3",
"type": "t3"
},
{
"name": "n4",
"value": "v4",
"type": "t4"
}
],
"gray": [
{
"name": "n5",
"value": "v5",
"type": "t5"
},
{
"name": "n6",
"value": "v6",
"type": "t6"
}
],
"red": [
{
"name": "n7",
"value": "v7",
"type": "t7"
}
]
}
}

--

You can set "include_in_root" to true on your nested objects and use
multi_match query with a wildcard:
{"multi_match":{"query":"v2","fields":["color.*.value"]}}. However, I would
recommend moving color into the nested object and complicating updates. :slight_smile:

On Thursday, December 20, 2012 3:49:58 PM UTC-5, Ash wrote:

Hi,

I've been try to use Elasticsearch to query heavily nested documents like
below (simplified document). In the document below, I would like to search
for all color values without having to specify a full "path" in nested
queries/filters. More like a wildcard path, for example color.*.value=v2 .
I could also include color types (blue, gray,red, etc) in the inner
objects and remove one level of nesting, but I need the nesting to update
(overwrite) a particular color type array (e.g. all blues). Including this
information in the inner object and decreasing nesting levels will
complicate updates.

If this is not possible, I would greatly appreciate it if I was pointed
in the right direction.
-Ash

{
"color": {
"blue": [
{
"name": "n3",
"value": "v3",
"type": "t3"
},
{
"name": "n4",
"value": "v4",
"type": "t4"
}
],
"gray": [
{
"name": "n5",
"value": "v5",
"type": "t5"
},
{
"name": "n6",
"value": "v6",
"type": "t6"
}
],
"red": [
{
"name": "n7",
"value": "v7",
"type": "t7"
}
]
}
}

--

Thank you for your reply.

Multi_match will only work if I was matching a single field. From what I
understand this would completely omit the structure of the data and I won't
be able to issue nested queries. As an example, the following query should
not return any hits, but it's not.

{
"query": {
"nested": {
"path": "color",
"query": {
"bool": {
"must": [
{"multi_match":{"query":"v3","fields":[
"color..value"]}},
{"multi_match":{"query":"n4","fields":[
"color.
.name"]}}
]
}
}
}
}
}

On Thursday, 20 December 2012 14:02:16 UTC-8, Igor Motov wrote:

You can set "include_in_root" to true on your nested objects and use
multi_match query with a wildcard:
{"multi_match":{"query":"v2","fields":["color.*.value"]}}. However, I
would recommend moving color into the nested object and complicating
updates. :slight_smile:

On Thursday, December 20, 2012 3:49:58 PM UTC-5, Ash wrote:

Hi,

I've been try to use Elasticsearch to query heavily nested documents like
below (simplified document). In the document below, I would like to search
for all color values without having to specify a full "path" in nested
queries/filters. More like a wildcard path, for example color.*.value=v2
.
I could also include color types (blue, gray,red, etc) in the inner
objects and remove one level of nesting, but I need the nesting to update
(overwrite) a particular color type array (e.g. all blues). Including this
information in the inner object and decreasing nesting levels will
complicate updates.

If this is not possible, I would greatly appreciate it if I was pointed
in the right direction.
-Ash

{
"color": {
"blue": [
{
"name": "n3",
"value": "v3",
"type": "t3"
},
{
"name": "n4",
"value": "v4",
"type": "t4"
}
],
"gray": [
{
"name": "n5",
"value": "v5",
"type": "t5"
},
{
"name": "n6",
"value": "v6",
"type": "t6"
}
],
"red": [
{
"name": "n7",
"value": "v7",
"type": "t7"
}
]
}
}

--

Exactly! That's why I recommended moving color into the nested object.

On Thursday, December 20, 2012 7:22:40 PM UTC-5, Ash wrote:

Thank you for your reply.

Multi_match will only work if I was matching a single field. From what I
understand this would completely omit the structure of the data and I won't
be able to issue nested queries. As an example, the following query should
not return any hits, but it's not.

{
"query": {
"nested": {
"path": "color",
"query": {
"bool": {
"must": [
{"multi_match":{"query":"v3","fields":[
"color..value"]}},
{"multi_match":{"query":"n4","fields":[
"color.
.name"]}}
]
}
}
}
}
}

On Thursday, 20 December 2012 14:02:16 UTC-8, Igor Motov wrote:

You can set "include_in_root" to true on your nested objects and use
multi_match query with a wildcard:
{"multi_match":{"query":"v2","fields":["color.*.value"]}}. However, I
would recommend moving color into the nested object and complicating
updates. :slight_smile:

On Thursday, December 20, 2012 3:49:58 PM UTC-5, Ash wrote:

Hi,

I've been try to use Elasticsearch to query heavily nested documents
like below (simplified document). In the document below, I would like to
search for all color values without having to specify a full "path" in
nested queries/filters. More like a wildcard path, for example
color.*.value=v2 .
I could also include color types (blue, gray,red, etc) in the inner
objects and remove one level of nesting, but I need the nesting to update
(overwrite) a particular color type array (e.g. all blues). Including this
information in the inner object and decreasing nesting levels will
complicate updates.

If this is not possible, I would greatly appreciate it if I was pointed
in the right direction.
-Ash

{
"color": {
"blue": [
{
"name": "n3",
"value": "v3",
"type": "t3"
},
{
"name": "n4",
"value": "v4",
"type": "t4"
}
],
"gray": [
{
"name": "n5",
"value": "v5",
"type": "t5"
},
{
"name": "n6",
"value": "v6",
"type": "t6"
}
],
"red": [
{
"name": "n7",
"value": "v7",
"type": "t7"
}
]
}
}

--

Thank you for clarifying this.

On Thursday, 20 December 2012 16:29:16 UTC-8, Igor Motov wrote:

Exactly! That's why I recommended moving color into the nested object.

On Thursday, December 20, 2012 7:22:40 PM UTC-5, Ash wrote:

Thank you for your reply.

Multi_match will only work if I was matching a single field. From what I
understand this would completely omit the structure of the data and I won't
be able to issue nested queries. As an example, the following query should
not return any hits, but it's not.

{
"query": {
"nested": {
"path": "color",
"query": {
"bool": {
"must": [
{"multi_match":{"query":"v3","fields":[
"color..value"]}},
{"multi_match":{"query":"n4","fields":[
"color.
.name"]}}
]
}
}
}
}
}

On Thursday, 20 December 2012 14:02:16 UTC-8, Igor Motov wrote:

You can set "include_in_root" to true on your nested objects and use
multi_match query with a wildcard:
{"multi_match":{"query":"v2","fields":["color.*.value"]}}. However, I
would recommend moving color into the nested object and complicating
updates. :slight_smile:

On Thursday, December 20, 2012 3:49:58 PM UTC-5, Ash wrote:

Hi,

I've been try to use Elasticsearch to query heavily nested documents
like below (simplified document). In the document below, I would like to
search for all color values without having to specify a full "path" in
nested queries/filters. More like a wildcard path, for example
color.*.value=v2 .
I could also include color types (blue, gray,red, etc) in the inner
objects and remove one level of nesting, but I need the nesting to update
(overwrite) a particular color type array (e.g. all blues). Including this
information in the inner object and decreasing nesting levels will
complicate updates.

If this is not possible, I would greatly appreciate it if I was
pointed in the right direction.
-Ash

{
"color": {
"blue": [
{
"name": "n3",
"value": "v3",
"type": "t3"
},
{
"name": "n4",
"value": "v4",
"type": "t4"
}
],
"gray": [
{
"name": "n5",
"value": "v5",
"type": "t5"
},
{
"name": "n6",
"value": "v6",
"type": "t6"
}
],
"red": [
{
"name": "n7",
"value": "v7",
"type": "t7"
}
]
}
}

--