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"}
}
]
}
}
}
elasticsearch elasticsearch-6
add a comment |
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"}
}
]
}
}
}
elasticsearch elasticsearch-6
add a comment |
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"}
}
]
}
}
}
elasticsearch elasticsearch-6
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
elasticsearch elasticsearch-6
edited Nov 11 at 4:41
asked Oct 24 at 11:30
Ajinkya Ranade
164
164
add a comment |
add a comment |
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
}
}
}
add a comment |
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
add a comment |
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
}
}
}
add a comment |
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
}
}
}
add a comment |
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
}
}
}
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
}
}
}
answered Oct 26 at 6:11
Ajinkya Ranade
164
164
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 11 at 4:39
Ajinkya Ranade
164
164
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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