How does one do negative queries against nested objects in Elasticsearch?Making an elasticsearch nested query for match on all fields of nested objectFilter nested objects in elasticsearch query based on querywhat does _doc represents in elasticsearch?ElasticSearch | Bool QueryElasticSearch: merge all inner_hits for nested queriesElasticsearch: Querying nested objectsNested Elasticsearch queriesElasticsearch with nested objects query
60's or earlier fantasy about two children pranksters who turn out to be persian deities
"One step behind" or "one move too late"
If password expiration is applied, should door-lock expiration be applied too?
How can I offer my prayers to an atheist colleague facing a serious personal situation?
A New Math Operation?
Can I call the airport to see if my boyfriend made it through customs?
How do you call a note, that stays through the whole song?
How does "unlimited holidays" work in practice?
How to retain new users on a Q&A site effectively?
What will happen to a ball kept on a frictionless inclined plane?
What mathematics activities get students physically moving?
Messed up my .bash_profile remotely, can't ssh back in
What is the largest piece of space debris volumetrically?
How does Wall of Roots interact with +1/+1 counters?
What is this nut?
Does a Paladin with the Divine Health feature destroy a Green Slime?
My advisor wants me to make my PhD thesis weaker
What is the difference between "cat < filename" and "cat filename"?
Did the US embassy in Kyiv resist hanging Trump's picture while Yovanovitch was ambassador?
How to indicate "photograph by"
How can I run a realistic open-world game with vast power differences, without resulting in constant TPKs?
For given two integers A and B, find a pair of numbers X and Y such that A = X*Y and B = X xor Y
What anti-aircraft magic adaptation would be better for dragons than flame spitting?
Regarding New Zealand Tourist Visa validity
How does one do negative queries against nested objects in Elasticsearch?
Making an elasticsearch nested query for match on all fields of nested objectFilter nested objects in elasticsearch query based on querywhat does _doc represents in elasticsearch?ElasticSearch | Bool QueryElasticSearch: merge all inner_hits for nested queriesElasticsearch: Querying nested objectsNested Elasticsearch queriesElasticsearch with nested objects query
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I have an index whose documents contain a list of nested objects. A simplified version of the mappings is as follows:
"_doc":
"dynamic": "strict",
"properties":
"things":
"type": "nested",
"dynamic": "strict",
"properties":
"name":
"type": "keyword"
,
"version":
"type": "keyword"
I want to get all documents that do not have any nested thing-objects with a specific set of values. Queries like
"query":
"nested":
"path": "things",
"query":
"bool":
"must_not": [
"term":
"name": "thing1"
,
"term":
"version": "1.0.0"
]
appear to just return all documents that have some nested document that doesn't match... which means it still returns all documents, even those that also do have a nested object which matches. So, how do I properly filter those out?
EDIT: Queries like
"query":
"bool":
"must_not": [
"nested":
"path": "things",
"query":
"bool":
"must": [
"term":
"name": "thing1"
,
"term":
"version": "1.0.0"
]
]
which nest the nested object query inside a must_not
also do not work, and still just return everything.
elasticsearch
add a comment
|
I have an index whose documents contain a list of nested objects. A simplified version of the mappings is as follows:
"_doc":
"dynamic": "strict",
"properties":
"things":
"type": "nested",
"dynamic": "strict",
"properties":
"name":
"type": "keyword"
,
"version":
"type": "keyword"
I want to get all documents that do not have any nested thing-objects with a specific set of values. Queries like
"query":
"nested":
"path": "things",
"query":
"bool":
"must_not": [
"term":
"name": "thing1"
,
"term":
"version": "1.0.0"
]
appear to just return all documents that have some nested document that doesn't match... which means it still returns all documents, even those that also do have a nested object which matches. So, how do I properly filter those out?
EDIT: Queries like
"query":
"bool":
"must_not": [
"nested":
"path": "things",
"query":
"bool":
"must": [
"term":
"name": "thing1"
,
"term":
"version": "1.0.0"
]
]
which nest the nested object query inside a must_not
also do not work, and still just return everything.
elasticsearch
As far as I know: Your nested query will apply to what is found, but for that nested type. What you probably want is a wrapper function to make your query nested query itself amust
, but your actual query:query: bool: must_not: [ nestedQuery - that does find things ]
It's not ideal, but a workaround I found
– Tessmore
Mar 28 at 22:44
@Tessmore Sadly, that doesn't appear to work, either. :(
– Logan R. Kearsley
Mar 28 at 23:12
1
Oki, I might not understand completely: If you don't wantthing1
as a name ORversion = 1.0.0
then the nested thingy can be ashould
and now that I read it again, I think that is what you mean? So the bool query inside the nested query can beshould
. If your use-case is different, maybe show an example document that matches and one that should not (but is now being returned)
– Tessmore
Mar 28 at 23:30
add a comment
|
I have an index whose documents contain a list of nested objects. A simplified version of the mappings is as follows:
"_doc":
"dynamic": "strict",
"properties":
"things":
"type": "nested",
"dynamic": "strict",
"properties":
"name":
"type": "keyword"
,
"version":
"type": "keyword"
I want to get all documents that do not have any nested thing-objects with a specific set of values. Queries like
"query":
"nested":
"path": "things",
"query":
"bool":
"must_not": [
"term":
"name": "thing1"
,
"term":
"version": "1.0.0"
]
appear to just return all documents that have some nested document that doesn't match... which means it still returns all documents, even those that also do have a nested object which matches. So, how do I properly filter those out?
EDIT: Queries like
"query":
"bool":
"must_not": [
"nested":
"path": "things",
"query":
"bool":
"must": [
"term":
"name": "thing1"
,
"term":
"version": "1.0.0"
]
]
which nest the nested object query inside a must_not
also do not work, and still just return everything.
elasticsearch
I have an index whose documents contain a list of nested objects. A simplified version of the mappings is as follows:
"_doc":
"dynamic": "strict",
"properties":
"things":
"type": "nested",
"dynamic": "strict",
"properties":
"name":
"type": "keyword"
,
"version":
"type": "keyword"
I want to get all documents that do not have any nested thing-objects with a specific set of values. Queries like
"query":
"nested":
"path": "things",
"query":
"bool":
"must_not": [
"term":
"name": "thing1"
,
"term":
"version": "1.0.0"
]
appear to just return all documents that have some nested document that doesn't match... which means it still returns all documents, even those that also do have a nested object which matches. So, how do I properly filter those out?
EDIT: Queries like
"query":
"bool":
"must_not": [
"nested":
"path": "things",
"query":
"bool":
"must": [
"term":
"name": "thing1"
,
"term":
"version": "1.0.0"
]
]
which nest the nested object query inside a must_not
also do not work, and still just return everything.
elasticsearch
elasticsearch
edited Mar 28 at 23:11
Logan R. Kearsley
asked Mar 28 at 22:03
Logan R. KearsleyLogan R. Kearsley
4434 silver badges14 bronze badges
4434 silver badges14 bronze badges
As far as I know: Your nested query will apply to what is found, but for that nested type. What you probably want is a wrapper function to make your query nested query itself amust
, but your actual query:query: bool: must_not: [ nestedQuery - that does find things ]
It's not ideal, but a workaround I found
– Tessmore
Mar 28 at 22:44
@Tessmore Sadly, that doesn't appear to work, either. :(
– Logan R. Kearsley
Mar 28 at 23:12
1
Oki, I might not understand completely: If you don't wantthing1
as a name ORversion = 1.0.0
then the nested thingy can be ashould
and now that I read it again, I think that is what you mean? So the bool query inside the nested query can beshould
. If your use-case is different, maybe show an example document that matches and one that should not (but is now being returned)
– Tessmore
Mar 28 at 23:30
add a comment
|
As far as I know: Your nested query will apply to what is found, but for that nested type. What you probably want is a wrapper function to make your query nested query itself amust
, but your actual query:query: bool: must_not: [ nestedQuery - that does find things ]
It's not ideal, but a workaround I found
– Tessmore
Mar 28 at 22:44
@Tessmore Sadly, that doesn't appear to work, either. :(
– Logan R. Kearsley
Mar 28 at 23:12
1
Oki, I might not understand completely: If you don't wantthing1
as a name ORversion = 1.0.0
then the nested thingy can be ashould
and now that I read it again, I think that is what you mean? So the bool query inside the nested query can beshould
. If your use-case is different, maybe show an example document that matches and one that should not (but is now being returned)
– Tessmore
Mar 28 at 23:30
As far as I know: Your nested query will apply to what is found, but for that nested type. What you probably want is a wrapper function to make your query nested query itself a
must
, but your actual query: query: bool: must_not: [ nestedQuery - that does find things ]
It's not ideal, but a workaround I found– Tessmore
Mar 28 at 22:44
As far as I know: Your nested query will apply to what is found, but for that nested type. What you probably want is a wrapper function to make your query nested query itself a
must
, but your actual query: query: bool: must_not: [ nestedQuery - that does find things ]
It's not ideal, but a workaround I found– Tessmore
Mar 28 at 22:44
@Tessmore Sadly, that doesn't appear to work, either. :(
– Logan R. Kearsley
Mar 28 at 23:12
@Tessmore Sadly, that doesn't appear to work, either. :(
– Logan R. Kearsley
Mar 28 at 23:12
1
1
Oki, I might not understand completely: If you don't want
thing1
as a name OR version = 1.0.0
then the nested thingy can be a should
and now that I read it again, I think that is what you mean? So the bool query inside the nested query can be should
. If your use-case is different, maybe show an example document that matches and one that should not (but is now being returned)– Tessmore
Mar 28 at 23:30
Oki, I might not understand completely: If you don't want
thing1
as a name OR version = 1.0.0
then the nested thingy can be a should
and now that I read it again, I think that is what you mean? So the bool query inside the nested query can be should
. If your use-case is different, maybe show an example document that matches and one that should not (but is now being returned)– Tessmore
Mar 28 at 23:30
add a comment
|
1 Answer
1
active
oldest
votes
Well, I eventually figured it out myself. It turns out that, despite explicitly specifying the path
field in a nested object query already, the names of fields of nested objects still have to be fully qualified. Thus, this works:
"query":
"nested":
"path": "things",
"query":
"bool":
"must_not": [
"term":
"things.name": "thing1"
,
"term":
"things.version": "1.0.0"
]
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407538%2fhow-does-one-do-negative-queries-against-nested-objects-in-elasticsearch%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Well, I eventually figured it out myself. It turns out that, despite explicitly specifying the path
field in a nested object query already, the names of fields of nested objects still have to be fully qualified. Thus, this works:
"query":
"nested":
"path": "things",
"query":
"bool":
"must_not": [
"term":
"things.name": "thing1"
,
"term":
"things.version": "1.0.0"
]
add a comment
|
Well, I eventually figured it out myself. It turns out that, despite explicitly specifying the path
field in a nested object query already, the names of fields of nested objects still have to be fully qualified. Thus, this works:
"query":
"nested":
"path": "things",
"query":
"bool":
"must_not": [
"term":
"things.name": "thing1"
,
"term":
"things.version": "1.0.0"
]
add a comment
|
Well, I eventually figured it out myself. It turns out that, despite explicitly specifying the path
field in a nested object query already, the names of fields of nested objects still have to be fully qualified. Thus, this works:
"query":
"nested":
"path": "things",
"query":
"bool":
"must_not": [
"term":
"things.name": "thing1"
,
"term":
"things.version": "1.0.0"
]
Well, I eventually figured it out myself. It turns out that, despite explicitly specifying the path
field in a nested object query already, the names of fields of nested objects still have to be fully qualified. Thus, this works:
"query":
"nested":
"path": "things",
"query":
"bool":
"must_not": [
"term":
"things.name": "thing1"
,
"term":
"things.version": "1.0.0"
]
answered Apr 16 at 17:32
Logan R. KearsleyLogan R. Kearsley
4434 silver badges14 bronze badges
4434 silver badges14 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407538%2fhow-does-one-do-negative-queries-against-nested-objects-in-elasticsearch%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
As far as I know: Your nested query will apply to what is found, but for that nested type. What you probably want is a wrapper function to make your query nested query itself a
must
, but your actual query:query: bool: must_not: [ nestedQuery - that does find things ]
It's not ideal, but a workaround I found– Tessmore
Mar 28 at 22:44
@Tessmore Sadly, that doesn't appear to work, either. :(
– Logan R. Kearsley
Mar 28 at 23:12
1
Oki, I might not understand completely: If you don't want
thing1
as a name ORversion = 1.0.0
then the nested thingy can be ashould
and now that I read it again, I think that is what you mean? So the bool query inside the nested query can beshould
. If your use-case is different, maybe show an example document that matches and one that should not (but is now being returned)– Tessmore
Mar 28 at 23:30