Spring MongoDb: Create indexes about unknown fields using bean classes



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








0















I'm running against an issue I don't know whether it's possible to do.



I need to store a document class with known fields, but also I need to store it with unknown fields:



@Document
public class Metadata

@Indexed
private String user;

private Object metadata;



All these unknown fields are stored inside metadata field.



However, I know someone of them. I mean, inside metadata field there will be whichever thing user wants, but there're some fields application knows.



I'd like to know how to create indexes about these unknown-knowed metadata fields.



Example:



 user: user, metadata: known: v, unknown: nv }


I'd like to create an index at metadata.known field.



The problem is, since this field is not set a a java bean field, I'm not able to annotated it as @Indexed.



Any ideas?










share|improve this question




























    0















    I'm running against an issue I don't know whether it's possible to do.



    I need to store a document class with known fields, but also I need to store it with unknown fields:



    @Document
    public class Metadata

    @Indexed
    private String user;

    private Object metadata;



    All these unknown fields are stored inside metadata field.



    However, I know someone of them. I mean, inside metadata field there will be whichever thing user wants, but there're some fields application knows.



    I'd like to know how to create indexes about these unknown-knowed metadata fields.



    Example:



     user: user, metadata: known: v, unknown: nv }


    I'd like to create an index at metadata.known field.



    The problem is, since this field is not set a a java bean field, I'm not able to annotated it as @Indexed.



    Any ideas?










    share|improve this question
























      0












      0








      0








      I'm running against an issue I don't know whether it's possible to do.



      I need to store a document class with known fields, but also I need to store it with unknown fields:



      @Document
      public class Metadata

      @Indexed
      private String user;

      private Object metadata;



      All these unknown fields are stored inside metadata field.



      However, I know someone of them. I mean, inside metadata field there will be whichever thing user wants, but there're some fields application knows.



      I'd like to know how to create indexes about these unknown-knowed metadata fields.



      Example:



       user: user, metadata: known: v, unknown: nv }


      I'd like to create an index at metadata.known field.



      The problem is, since this field is not set a a java bean field, I'm not able to annotated it as @Indexed.



      Any ideas?










      share|improve this question














      I'm running against an issue I don't know whether it's possible to do.



      I need to store a document class with known fields, but also I need to store it with unknown fields:



      @Document
      public class Metadata

      @Indexed
      private String user;

      private Object metadata;



      All these unknown fields are stored inside metadata field.



      However, I know someone of them. I mean, inside metadata field there will be whichever thing user wants, but there're some fields application knows.



      I'd like to know how to create indexes about these unknown-knowed metadata fields.



      Example:



       user: user, metadata: known: v, unknown: nv }


      I'd like to create an index at metadata.known field.



      The problem is, since this field is not set a a java bean field, I'm not able to annotated it as @Indexed.



      Any ideas?







      spring spring-data-mongodb






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 14:44









      JordiJordi

      4,59493989




      4,59493989






















          2 Answers
          2






          active

          oldest

          votes


















          0














          As a guess, why don't you split the metadata Object in two?



          One for known fields that you can index and other for the unknown that you cannot index. For example:



          @Document
          public class Metadata

          @Indexed
          private String user;

          @Indexed
          private Object knownMetadata;

          private Object unknownMetadata;




          As a result you will have something similar to:



           user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }





          share|improve this answer























          • Are All knownMetadata sub-fields indexed?

            – Jordi
            Nov 15 '18 at 14:56











          • Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject

            – juanlumn
            Nov 15 '18 at 15:12


















          0














          For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.



          Consider this bean:



          @CompoundIndexes(
          @CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
          )
          @Document
          @Document
          public class Metadata

          @Indexed
          private String user;

          private Object metadata;



          This would now create an index on the field: metadata.known - you can do this on any of the known fields and define them in the annotation.






          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%2f53321949%2fspring-mongodb-create-indexes-about-unknown-fields-using-bean-classes%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            As a guess, why don't you split the metadata Object in two?



            One for known fields that you can index and other for the unknown that you cannot index. For example:



            @Document
            public class Metadata

            @Indexed
            private String user;

            @Indexed
            private Object knownMetadata;

            private Object unknownMetadata;




            As a result you will have something similar to:



             user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }





            share|improve this answer























            • Are All knownMetadata sub-fields indexed?

              – Jordi
              Nov 15 '18 at 14:56











            • Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject

              – juanlumn
              Nov 15 '18 at 15:12















            0














            As a guess, why don't you split the metadata Object in two?



            One for known fields that you can index and other for the unknown that you cannot index. For example:



            @Document
            public class Metadata

            @Indexed
            private String user;

            @Indexed
            private Object knownMetadata;

            private Object unknownMetadata;




            As a result you will have something similar to:



             user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }





            share|improve this answer























            • Are All knownMetadata sub-fields indexed?

              – Jordi
              Nov 15 '18 at 14:56











            • Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject

              – juanlumn
              Nov 15 '18 at 15:12













            0












            0








            0







            As a guess, why don't you split the metadata Object in two?



            One for known fields that you can index and other for the unknown that you cannot index. For example:



            @Document
            public class Metadata

            @Indexed
            private String user;

            @Indexed
            private Object knownMetadata;

            private Object unknownMetadata;




            As a result you will have something similar to:



             user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }





            share|improve this answer













            As a guess, why don't you split the metadata Object in two?



            One for known fields that you can index and other for the unknown that you cannot index. For example:



            @Document
            public class Metadata

            @Indexed
            private String user;

            @Indexed
            private Object knownMetadata;

            private Object unknownMetadata;




            As a result you will have something similar to:



             user: user, knownMetadata: knownField1: v, knownField2: nv, unknownMetadata: unknownField1: v, unknownField2: nv }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 '18 at 14:53









            juanlumnjuanlumn

            2,0291722




            2,0291722












            • Are All knownMetadata sub-fields indexed?

              – Jordi
              Nov 15 '18 at 14:56











            • Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject

              – juanlumn
              Nov 15 '18 at 15:12

















            • Are All knownMetadata sub-fields indexed?

              – Jordi
              Nov 15 '18 at 14:56











            • Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject

              – juanlumn
              Nov 15 '18 at 15:12
















            Are All knownMetadata sub-fields indexed?

            – Jordi
            Nov 15 '18 at 14:56





            Are All knownMetadata sub-fields indexed?

            – Jordi
            Nov 15 '18 at 14:56













            Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject

            – juanlumn
            Nov 15 '18 at 15:12





            Not sure about that, how many known fields you have in the metadata? I'm asking because you can always create a an @Indexed field for each known parameter and keep the unknown in the metadataObject

            – juanlumn
            Nov 15 '18 at 15:12













            0














            For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.



            Consider this bean:



            @CompoundIndexes(
            @CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
            )
            @Document
            @Document
            public class Metadata

            @Indexed
            private String user;

            private Object metadata;



            This would now create an index on the field: metadata.known - you can do this on any of the known fields and define them in the annotation.






            share|improve this answer



























              0














              For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.



              Consider this bean:



              @CompoundIndexes(
              @CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
              )
              @Document
              @Document
              public class Metadata

              @Indexed
              private String user;

              private Object metadata;



              This would now create an index on the field: metadata.known - you can do this on any of the known fields and define them in the annotation.






              share|improve this answer

























                0












                0








                0







                For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.



                Consider this bean:



                @CompoundIndexes(
                @CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
                )
                @Document
                @Document
                public class Metadata

                @Indexed
                private String user;

                private Object metadata;



                This would now create an index on the field: metadata.known - you can do this on any of the known fields and define them in the annotation.






                share|improve this answer













                For known fields you can create an index with the compound index annotation. It does not actually force you to have a compound index.



                Consider this bean:



                @CompoundIndexes(
                @CompoundIndex(name="my_index", def = "'metadata.known' : 1", background=true),
                )
                @Document
                @Document
                public class Metadata

                @Indexed
                private String user;

                private Object metadata;



                This would now create an index on the field: metadata.known - you can do this on any of the known fields and define them in the annotation.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 15:12









                pandaadbpandaadb

                4,63111226




                4,63111226



























                    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%2f53321949%2fspring-mongodb-create-indexes-about-unknown-fields-using-bean-classes%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 how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20