How to verify input value is within range or not in elastic search Using DSL QUERY











up vote
0
down vote

favorite












I have two entity like User & Activity. Activity contains filed ageGroup like ["10:20","25:30"] & user entity contained age field . consider user age is 26 so he/she is eligible for that activity.
I want to fetch all those activities which satisfied above conditions



GET _search
{
"query": {

"bool": {
"filter": {
"range": {
"ageGroup": {
"gte": 50,
"lte": 55
}
},
"term": {"****": "M"}
},
"must": [
{
"term": {"******": {"value": "15"}}

}
] ,"should": [
{
"match": {"******": "7"}
},
{
"match": {"******": "1"}
}
]
}
}
}









share|improve this question




























    up vote
    0
    down vote

    favorite












    I have two entity like User & Activity. Activity contains filed ageGroup like ["10:20","25:30"] & user entity contained age field . consider user age is 26 so he/she is eligible for that activity.
    I want to fetch all those activities which satisfied above conditions



    GET _search
    {
    "query": {

    "bool": {
    "filter": {
    "range": {
    "ageGroup": {
    "gte": 50,
    "lte": 55
    }
    },
    "term": {"****": "M"}
    },
    "must": [
    {
    "term": {"******": {"value": "15"}}

    }
    ] ,"should": [
    {
    "match": {"******": "7"}
    },
    {
    "match": {"******": "1"}
    }
    ]
    }
    }
    }









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have two entity like User & Activity. Activity contains filed ageGroup like ["10:20","25:30"] & user entity contained age field . consider user age is 26 so he/she is eligible for that activity.
      I want to fetch all those activities which satisfied above conditions



      GET _search
      {
      "query": {

      "bool": {
      "filter": {
      "range": {
      "ageGroup": {
      "gte": 50,
      "lte": 55
      }
      },
      "term": {"****": "M"}
      },
      "must": [
      {
      "term": {"******": {"value": "15"}}

      }
      ] ,"should": [
      {
      "match": {"******": "7"}
      },
      {
      "match": {"******": "1"}
      }
      ]
      }
      }
      }









      share|improve this question















      I have two entity like User & Activity. Activity contains filed ageGroup like ["10:20","25:30"] & user entity contained age field . consider user age is 26 so he/she is eligible for that activity.
      I want to fetch all those activities which satisfied above conditions



      GET _search
      {
      "query": {

      "bool": {
      "filter": {
      "range": {
      "ageGroup": {
      "gte": 50,
      "lte": 55
      }
      },
      "term": {"****": "M"}
      },
      "must": [
      {
      "term": {"******": {"value": "15"}}

      }
      ] ,"should": [
      {
      "match": {"******": "7"}
      },
      {
      "match": {"******": "1"}
      }
      ]
      }
      }
      }






      elasticsearch elasticsearch-6






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 4:41

























      asked Oct 24 at 11:30









      Ajinkya Ranade

      164




      164
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          Include(Entity/Object) contain List



          public class Include {
          @Field(type= FieldType.Nested)
          private List<AgeGroup> age;
          }


          Data :
          {....., include.age:{ "id": 4, "minAge": 4, "maxAge": 9 }, { "id": 3, "minAge": 1, "maxAge": 4 }, .....}



          DSL Query :



          GET /_search
          {
          "query": {

          "bool": {
          "should": [
          {"range": {"include.age.minAge": {"lte": 9}}},
          {"range": {"include.age.maxAge": {"gte": 9}}
          }
          ],"minimum_should_match": 2
          }

          }
          }





          share|improve this answer




























            up vote
            0
            down vote



            accepted










            You can also use integer_range data type to verify value within range or not
            https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html






            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',
              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%2f52967865%2fhow-to-verify-input-value-is-within-range-or-not-in-elastic-search-using-dsl-que%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








              up vote
              0
              down vote













              Include(Entity/Object) contain List



              public class Include {
              @Field(type= FieldType.Nested)
              private List<AgeGroup> age;
              }


              Data :
              {....., include.age:{ "id": 4, "minAge": 4, "maxAge": 9 }, { "id": 3, "minAge": 1, "maxAge": 4 }, .....}



              DSL Query :



              GET /_search
              {
              "query": {

              "bool": {
              "should": [
              {"range": {"include.age.minAge": {"lte": 9}}},
              {"range": {"include.age.maxAge": {"gte": 9}}
              }
              ],"minimum_should_match": 2
              }

              }
              }





              share|improve this answer

























                up vote
                0
                down vote













                Include(Entity/Object) contain List



                public class Include {
                @Field(type= FieldType.Nested)
                private List<AgeGroup> age;
                }


                Data :
                {....., include.age:{ "id": 4, "minAge": 4, "maxAge": 9 }, { "id": 3, "minAge": 1, "maxAge": 4 }, .....}



                DSL Query :



                GET /_search
                {
                "query": {

                "bool": {
                "should": [
                {"range": {"include.age.minAge": {"lte": 9}}},
                {"range": {"include.age.maxAge": {"gte": 9}}
                }
                ],"minimum_should_match": 2
                }

                }
                }





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Include(Entity/Object) contain List



                  public class Include {
                  @Field(type= FieldType.Nested)
                  private List<AgeGroup> age;
                  }


                  Data :
                  {....., include.age:{ "id": 4, "minAge": 4, "maxAge": 9 }, { "id": 3, "minAge": 1, "maxAge": 4 }, .....}



                  DSL Query :



                  GET /_search
                  {
                  "query": {

                  "bool": {
                  "should": [
                  {"range": {"include.age.minAge": {"lte": 9}}},
                  {"range": {"include.age.maxAge": {"gte": 9}}
                  }
                  ],"minimum_should_match": 2
                  }

                  }
                  }





                  share|improve this answer












                  Include(Entity/Object) contain List



                  public class Include {
                  @Field(type= FieldType.Nested)
                  private List<AgeGroup> age;
                  }


                  Data :
                  {....., include.age:{ "id": 4, "minAge": 4, "maxAge": 9 }, { "id": 3, "minAge": 1, "maxAge": 4 }, .....}



                  DSL Query :



                  GET /_search
                  {
                  "query": {

                  "bool": {
                  "should": [
                  {"range": {"include.age.minAge": {"lte": 9}}},
                  {"range": {"include.age.maxAge": {"gte": 9}}
                  }
                  ],"minimum_should_match": 2
                  }

                  }
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 26 at 6:11









                  Ajinkya Ranade

                  164




                  164
























                      up vote
                      0
                      down vote



                      accepted










                      You can also use integer_range data type to verify value within range or not
                      https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html






                      share|improve this answer

























                        up vote
                        0
                        down vote



                        accepted










                        You can also use integer_range data type to verify value within range or not
                        https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html






                        share|improve this answer























                          up vote
                          0
                          down vote



                          accepted







                          up vote
                          0
                          down vote



                          accepted






                          You can also use integer_range data type to verify value within range or not
                          https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html






                          share|improve this answer












                          You can also use integer_range data type to verify value within range or not
                          https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 11 at 4:39









                          Ajinkya Ranade

                          164




                          164






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52967865%2fhow-to-verify-input-value-is-within-range-or-not-in-elastic-search-using-dsl-que%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

                              Xamarin.iOS Cant Deploy on Iphone

                              Glorious Revolution

                              Dulmage-Mendelsohn matrix decomposition in Python