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

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?