Id Field Data
--------------------------------------------------
1 A Data1
2 B Data2
2 C Data3
3 C Data4
4 G Data5
5 F Data6
5 B Data7
I want with a single query (for pagination) to fetch all fields "Data" with an Id containing at least one Field with a value of A, B, C. In the previous example I should retrieve all except "Data5" because Id 4 is the only one that does not contain A, B or C . Expected result: Data1, Data2, Data3, Data4, Data6, Data7.
Thanks, I am newbie with ES and I made a mess with must, should, filters, ....
The following might be helpful to you.
{
"query": {
"bool": {
"must_not": [
{
"terms": {
"Field": ["G"]
}
}
]
}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
Related
I have a problem. I am using the https://rickandmortyapi.com/graphql API for graphql. I want to query the amount of character which are between epiosde 1 and 2 with the name Rick. Unfortunately my query is wrong. How could I get the desired output. I want to use the _" ..."Meta to get the meta data.
query {
characters(filter: {name: "Rick"}) {
_episode(filter: {id : 1
id: 2}) {
count
}
}
}
Hi I need help writing query.
doc in ES is
{ A: "A", B: ["1","2"] }
result from query should be: hits(2x)
{ A:"A" , B: "1"},
{ A:"A" , B: "2" }
is this possible?
I would like to check if a number is in a specific range dynamically. For example i have a table like:
id
value
age_range
1
a
3-7
2
b
7-10
3
c
3-7
4
d
0-3
if the age of the user is 5, i would like to retrieve all rows where age_range is 3-7 without writing the range in the where clause query. For example something like:
table (where: { 5 in age_range })...
Make an age_from and an age_to column if possible.
query MyQuery($int: Int!) {
table(where: {_and: [{age_to: {_gte: $int}}, {age_from: {_lte: $int}}]}) {
#Fields....
}
}
I have an index with the following data:
{
"_index":"businesses",
"_type":"business",
"_id":"1",
"_version":1,
"found":true,
"_source":{
"business":{
"account_level_id":"2",
"business_city":"Abington",
"business_country":"United States of America",
}
}
}
When I query the index, I want to sort by account_level_id (which is a digit between 1-5). The problem is, I don't want to sort in ASC or DESC order, but by the following: 4..3..5..2..1. This was caused by bad practice a couple years ago, where the account level maxed out at level 4, but then a lower level account was added with the value of 5. Is there a way to tell ES that I want the results returned in that specific order?
You could write a sort based script something like (not tested):
doc['account_level_id'].value == "5" ? 3 : doc['account_level_id'].value == "4" ? 5 : doc['account_level_id'].value == "3" ? 4 : doc['account_level_id'].value == "2" ? 2 : 1;
Or if possible you could create another field sort_level that maps account_level_id to sensible values that you can sort on.
{
"_index":"businesses",
"_type":"business",
"_id":"1",
"_version":1,
"found":true,
"_source":{
"business":{
"account_level_id":"4",
"business_city":"Abington",
"business_country":"United States of America",
"sort_level": 5
}
}
}
If you can sort in DESC you can create function that maps integers and sort using it.
DESC should sort them like (5 4 3 2 1), 5 replaced by 4, 4 replaced by 3, 3 replaced by 5.
int map_to(int x){
switch(x){
case 1: case 2: return x;
case 3: return 4;
case 4: return 5;
case 5: return 3;
}
}
and use it for your sorting algorithm (so when sorting algorithm has to compare x vs y it should compare map_to(x) vs map_to(y) , and this will make 4 comes before 3 and 5 as you want.
I have a table with records like this
{
a:{aa:"aa1",aaa:"aaa1"},
b:"b1",
...
},
{
a:{aaa:"aaa2"},
b:"b2",
...
},
{
a:{aa:"aa3"},
b:"b3",
...
},
and I want to extract aa and b values, i.e. to something like
{aa:"aa1",b:"b1"},
{aa:undefined,b:"b2"},
{aa:"aa3",b:"b3"},
You can write something like:
o = {a: {aa: "aa1", aaa: "aaa1"}, b: "b1"}
r.expr(o).do({a: r.row('a')('aa').default(null), b: r.row('b').default(null)})