Filter for no nested documents


(Lisinge) #1

I have a mapping where we have N nested documents. Is there a way to filter
for documents which have no nested documents?
I've tried with the missinghttp://www.elasticsearch.org/guide/reference/query-dsl/missing-filter.html filter
without success.

--


(Martijn Van Groningen) #2

I think if you wrap the nested filter in a not filter, you get what you need.

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

Martijn

On 10 September 2012 10:56, Lisinge lisinge@rabble.se wrote:

I have a mapping where we have N nested documents. Is there a way to filter
for documents which have no nested documents?
I've tried with the missing filter without success.

--

--
Met vriendelijke groet,

Martijn van Groningen

--


(Lisinge) #3

Thanks for your reply Martijn.
I thought about that too. Could you give me an example of what you mean?

Den måndagen den 10:e september 2012 kl. 11:11:43 UTC+2 skrev Martijn v
Groningen:

I think if you wrap the nested filter in a not filter, you get what you
need.

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

Martijn

On 10 September 2012 10:56, Lisinge <lis...@rabble.se <javascript:>>
wrote:

I have a mapping where we have N nested documents. Is there a way to
filter
for documents which have no nested documents?
I've tried with the missing filter without success.

--

--
Met vriendelijke groet,

Martijn van Groningen

--


(Lisinge) #4

Here is also a simple example off the mapping that is used:

{

"created_at": {
"type": "date"
},
"checkouts": {
"type": "nested",
"properties": {
"location": {
"type": "geo_point"
},
"created_at": {
"type": "date"
}
}
}

Den måndagen den 10:e september 2012 kl. 11:11:43 UTC+2 skrev Martijn v
Groningen:

I think if you wrap the nested filter in a not filter, you get what you
need.

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

Martijn

On 10 September 2012 10:56, Lisinge <lis...@rabble.se <javascript:>>
wrote:

I have a mapping where we have N nested documents. Is there a way to
filter
for documents which have no nested documents?
I've tried with the missing filter without success.

--

--
Met vriendelijke groet,

Martijn van Groningen

--


(Martijn Van Groningen) #5

An example using the filtered query
(http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html):
{
"filtered" : {
"query" : { "match_all" : {} },
"filter" : {
"not" : {
"filter" : {
"nested" : {
"path" : "checkouts",
"query" : {
"match_all" : {}
}
}
},
"_cache" : true
}
}
}
}

The above query should return all docs that don't have nested documents.

On 10 September 2012 11:29, Lisinge lisinge@rabble.se wrote:

Here is also a simple example off the mapping that is used:

{
"created_at": {
"type": "date"
},
"checkouts": {
"type": "nested",
"properties": {
"location": {
"type": "geo_point"
},
"created_at": {
"type": "date"
}
}
}

Den måndagen den 10:e september 2012 kl. 11:11:43 UTC+2 skrev Martijn v
Groningen:

I think if you wrap the nested filter in a not filter, you get what you
need.

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

Martijn

On 10 September 2012 10:56, Lisinge lis...@rabble.se wrote:

I have a mapping where we have N nested documents. Is there a way to
filter
for documents which have no nested documents?
I've tried with the missing filter without success.

--

--
Met vriendelijke groet,

Martijn van Groningen

--

--
Met vriendelijke groet,

Martijn van Groningen

--


(Lisinge) #6

Thanks Martijn.

I ended up with this query:
{
"filter": {
"not": {
"nested": {
"path": "checkouts",
"filter": {
"match_all": {}
}
}
}
}
}

But i believe the "match_all" is kinda misleading, is there some other way
to do it?

Den måndagen den 10:e september 2012 kl. 11:38:20 UTC+2 skrev Martijn v
Groningen:

An example using the filtered query
(
http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html):

{
"filtered" : {
"query" : { "match_all" : {} },
"filter" : {
"not" : {
"filter" : {
"nested" : {
"path" : "checkouts",
"query" : {
"match_all" : {}
}
}
},
"_cache" : true
}
}
}
}

The above query should return all docs that don't have nested documents.

On 10 September 2012 11:29, Lisinge <lis...@rabble.se <javascript:>>
wrote:

Here is also a simple example off the mapping that is used:

{
"created_at": {
"type": "date"
},
"checkouts": {
"type": "nested",
"properties": {
"location": {
"type": "geo_point"
},
"created_at": {
"type": "date"
}
}
}

Den måndagen den 10:e september 2012 kl. 11:11:43 UTC+2 skrev Martijn v
Groningen:

I think if you wrap the nested filter in a not filter, you get what you
need.

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

Martijn

On 10 September 2012 10:56, Lisinge lis...@rabble.se wrote:

I have a mapping where we have N nested documents. Is there a way to
filter
for documents which have no nested documents?
I've tried with the missing filter without success.

--

--
Met vriendelijke groet,

Martijn van Groningen

--

--
Met vriendelijke groet,

Martijn van Groningen

--


(Martijn Van Groningen) #7

But i believe the "match_all" is kinda misleading, is there some other way
to do it?
What do you find misleading about the "match_all"? The match all
basically selects all documents on the nested checkouts level. I think
this is the best way to do this.

--


(system) #8