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;









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.










share|improve this question



























  • 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 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


















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.










share|improve this question



























  • 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 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














0













0









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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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 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


















  • 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 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

















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













1 Answer
1






active

oldest

votes


















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"


]










share|improve this answer



























    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
    );



    );














    draft saved

    draft discarded
















    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









    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"


    ]










    share|improve this answer






























      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"


      ]










      share|improve this answer




























        0















        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"


        ]










        share|improve this answer














        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"


        ]











        share|improve this answer













        share|improve this answer




        share|improve this answer










        answered Apr 16 at 17:32









        Logan R. KearsleyLogan R. Kearsley

        4434 silver badges14 bronze badges




        4434 silver badges14 bronze badges

































            draft saved

            draft discarded















































            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.




            draft saved


            draft discarded














            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





















































            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









            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript