Nested bool query with multiple must and shouldMultiple values in QueryString query using elasticsearch NESTElasticsearch query_string nested queryElasticsearch difference between MUST and SHOULD bool queryQuery two fields, one nested and one on the rootElastic Search: use filter and should bool query'must' and 'should' combined in bool query not workingMultiple Paths in Nested QueriesWill ElasticSearch performance differ if we have multiple nested queriesMultiple nested queries to the same path?Filtering query in elastic search for nested model

Is there a term for the belief that "if it's legal, it's moral"?

Did the CIA blow up a Siberian pipeline in 1982?

Non-misogynistic way to say “asshole”?

Too early in the morning to have SODA?

Can the pre-order traversal of two different trees be the same even though they are different?

Why is oilcloth made with linseed oil?

Methodology: Writing unit tests for another developer

Is there official documentation on directories like ~/.config and ~/.cache?

How do I remove this inheritance-related code smell?

Why don't countries like Japan just print more money?

Draw a symmetric alien head

How do I see debug logs for Change Data Capture triggers in Salesforce?

Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?

Do I have any obligations to my PhD supervisor's requests after I have graduated?

A word for delight at someone else's failure?

What is "industrial ethernet"?

"Correct me if I'm wrong"

Drawing a second weapon as part of an attack?

Is "Busen" just the area between the breasts?

Subtract the Folded Matrix

How can I prevent a user from copying files on another hard drive?

What is the most suitable position for a bishop here?

What was the first third-party commercial application for MS-DOS?

Novel in which alien (Martian?) is trapped on Earth in prehistory



Nested bool query with multiple must and should


Multiple values in QueryString query using elasticsearch NESTElasticsearch query_string nested queryElasticsearch difference between MUST and SHOULD bool queryQuery two fields, one nested and one on the rootElastic Search: use filter and should bool query'must' and 'should' combined in bool query not workingMultiple Paths in Nested QueriesWill ElasticSearch performance differ if we have multiple nested queriesMultiple nested queries to the same path?Filtering query in elastic search for nested model






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















Look at my use case below



Two nested fields



base1.point1
base1.point2
base1.point3
base1.point4


and



base2.point1
base2.point2
base2.point3
base2.point4


search condition



(
(base1.point1 AND base1.point2) OR (base1.point2 AND base1.point3)
)
AND
(
(base2.point1 AND base2.point2) OR (base2.point2 AND base2.point3)
)


Please help for writing above in a single query.










share|improve this question






























    1















    Look at my use case below



    Two nested fields



    base1.point1
    base1.point2
    base1.point3
    base1.point4


    and



    base2.point1
    base2.point2
    base2.point3
    base2.point4


    search condition



    (
    (base1.point1 AND base1.point2) OR (base1.point2 AND base1.point3)
    )
    AND
    (
    (base2.point1 AND base2.point2) OR (base2.point2 AND base2.point3)
    )


    Please help for writing above in a single query.










    share|improve this question


























      1












      1








      1


      1






      Look at my use case below



      Two nested fields



      base1.point1
      base1.point2
      base1.point3
      base1.point4


      and



      base2.point1
      base2.point2
      base2.point3
      base2.point4


      search condition



      (
      (base1.point1 AND base1.point2) OR (base1.point2 AND base1.point3)
      )
      AND
      (
      (base2.point1 AND base2.point2) OR (base2.point2 AND base2.point3)
      )


      Please help for writing above in a single query.










      share|improve this question
















      Look at my use case below



      Two nested fields



      base1.point1
      base1.point2
      base1.point3
      base1.point4


      and



      base2.point1
      base2.point2
      base2.point3
      base2.point4


      search condition



      (
      (base1.point1 AND base1.point2) OR (base1.point2 AND base1.point3)
      )
      AND
      (
      (base2.point1 AND base2.point2) OR (base2.point2 AND base2.point3)
      )


      Please help for writing above in a single query.







      elasticsearch elastic-stack






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 7:14









      emix

      7,48753254




      7,48753254










      asked Mar 25 at 7:09









      G2KG2K

      127




      127






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Note that I'm assuming that when you meant nested you are actually talking about Nested Datatype and not plain Object Datatype



          Also looking at your question, you are only concerned if the nested fields exists or not, regardless of their values. For such use cases you would need to make use of Exists Query.



          Below is how my Nested Query would be:



          POST <you_index_name>/_search

          "query":
          "bool":
          "must":[

          "bool":
          "should":[

          "bool":
          "must":[

          "nested":
          "path":"base1",
          "query":
          "exists":
          "field":"base1.point1"



          ,

          "nested":
          "path":"base1",
          "query":
          "exists":
          "field":"base1.point2"




          ]

          ,

          "bool":
          "must":[

          "nested":
          "path":"base1",
          "query":
          "exists":
          "field":"base1.point2"



          ,

          "nested":
          "path":"base1",
          "query":
          "exists":
          "field":"base1.point3"




          ]


          ]

          ,

          "bool":
          "should":[

          "bool":
          "must":[

          "nested":
          "path":"base2",
          "query":
          "exists":
          "field":"base2.point1"



          ,

          "nested":
          "path":"base1",
          "query":
          "exists":
          "field":"base2.point2"




          ]

          ,

          "bool":
          "must":[

          "nested":
          "path":"base2",
          "query":
          "exists":
          "field":"base2.point2"



          ,

          "nested":
          "path":"base2",
          "query":
          "exists":
          "field":"base2.point3"




          ]


          ]


          ]





          Hope this helps!






          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/3.0/"u003ecc by-sa 3.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%2f55332738%2fnested-bool-query-with-multiple-must-and-should%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














            Note that I'm assuming that when you meant nested you are actually talking about Nested Datatype and not plain Object Datatype



            Also looking at your question, you are only concerned if the nested fields exists or not, regardless of their values. For such use cases you would need to make use of Exists Query.



            Below is how my Nested Query would be:



            POST <you_index_name>/_search

            "query":
            "bool":
            "must":[

            "bool":
            "should":[

            "bool":
            "must":[

            "nested":
            "path":"base1",
            "query":
            "exists":
            "field":"base1.point1"



            ,

            "nested":
            "path":"base1",
            "query":
            "exists":
            "field":"base1.point2"




            ]

            ,

            "bool":
            "must":[

            "nested":
            "path":"base1",
            "query":
            "exists":
            "field":"base1.point2"



            ,

            "nested":
            "path":"base1",
            "query":
            "exists":
            "field":"base1.point3"




            ]


            ]

            ,

            "bool":
            "should":[

            "bool":
            "must":[

            "nested":
            "path":"base2",
            "query":
            "exists":
            "field":"base2.point1"



            ,

            "nested":
            "path":"base1",
            "query":
            "exists":
            "field":"base2.point2"




            ]

            ,

            "bool":
            "must":[

            "nested":
            "path":"base2",
            "query":
            "exists":
            "field":"base2.point2"



            ,

            "nested":
            "path":"base2",
            "query":
            "exists":
            "field":"base2.point3"




            ]


            ]


            ]





            Hope this helps!






            share|improve this answer





























              0














              Note that I'm assuming that when you meant nested you are actually talking about Nested Datatype and not plain Object Datatype



              Also looking at your question, you are only concerned if the nested fields exists or not, regardless of their values. For such use cases you would need to make use of Exists Query.



              Below is how my Nested Query would be:



              POST <you_index_name>/_search

              "query":
              "bool":
              "must":[

              "bool":
              "should":[

              "bool":
              "must":[

              "nested":
              "path":"base1",
              "query":
              "exists":
              "field":"base1.point1"



              ,

              "nested":
              "path":"base1",
              "query":
              "exists":
              "field":"base1.point2"




              ]

              ,

              "bool":
              "must":[

              "nested":
              "path":"base1",
              "query":
              "exists":
              "field":"base1.point2"



              ,

              "nested":
              "path":"base1",
              "query":
              "exists":
              "field":"base1.point3"




              ]


              ]

              ,

              "bool":
              "should":[

              "bool":
              "must":[

              "nested":
              "path":"base2",
              "query":
              "exists":
              "field":"base2.point1"



              ,

              "nested":
              "path":"base1",
              "query":
              "exists":
              "field":"base2.point2"




              ]

              ,

              "bool":
              "must":[

              "nested":
              "path":"base2",
              "query":
              "exists":
              "field":"base2.point2"



              ,

              "nested":
              "path":"base2",
              "query":
              "exists":
              "field":"base2.point3"




              ]


              ]


              ]





              Hope this helps!






              share|improve this answer



























                0












                0








                0







                Note that I'm assuming that when you meant nested you are actually talking about Nested Datatype and not plain Object Datatype



                Also looking at your question, you are only concerned if the nested fields exists or not, regardless of their values. For such use cases you would need to make use of Exists Query.



                Below is how my Nested Query would be:



                POST <you_index_name>/_search

                "query":
                "bool":
                "must":[

                "bool":
                "should":[

                "bool":
                "must":[

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base1.point1"



                ,

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base1.point2"




                ]

                ,

                "bool":
                "must":[

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base1.point2"



                ,

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base1.point3"




                ]


                ]

                ,

                "bool":
                "should":[

                "bool":
                "must":[

                "nested":
                "path":"base2",
                "query":
                "exists":
                "field":"base2.point1"



                ,

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base2.point2"




                ]

                ,

                "bool":
                "must":[

                "nested":
                "path":"base2",
                "query":
                "exists":
                "field":"base2.point2"



                ,

                "nested":
                "path":"base2",
                "query":
                "exists":
                "field":"base2.point3"




                ]


                ]


                ]





                Hope this helps!






                share|improve this answer















                Note that I'm assuming that when you meant nested you are actually talking about Nested Datatype and not plain Object Datatype



                Also looking at your question, you are only concerned if the nested fields exists or not, regardless of their values. For such use cases you would need to make use of Exists Query.



                Below is how my Nested Query would be:



                POST <you_index_name>/_search

                "query":
                "bool":
                "must":[

                "bool":
                "should":[

                "bool":
                "must":[

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base1.point1"



                ,

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base1.point2"




                ]

                ,

                "bool":
                "must":[

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base1.point2"



                ,

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base1.point3"




                ]


                ]

                ,

                "bool":
                "should":[

                "bool":
                "must":[

                "nested":
                "path":"base2",
                "query":
                "exists":
                "field":"base2.point1"



                ,

                "nested":
                "path":"base1",
                "query":
                "exists":
                "field":"base2.point2"




                ]

                ,

                "bool":
                "must":[

                "nested":
                "path":"base2",
                "query":
                "exists":
                "field":"base2.point2"



                ,

                "nested":
                "path":"base2",
                "query":
                "exists":
                "field":"base2.point3"




                ]


                ]


                ]





                Hope this helps!







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 25 at 9:00

























                answered Mar 25 at 8:43









                KamalKamal

                3,40721023




                3,40721023





























                    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%2f55332738%2fnested-bool-query-with-multiple-must-and-should%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