Вот часть моего запроса:
must_not: {
script: {
script: {
source: "doc['type.keyword'].value=='CHANNEL' ? doc['id'].value == 0 : doc['id'].value.contains(['1','3','7'])",
lang: 'painless'
}
}
}
Как я могу проверить, имеет ли doc['id'].value
значение из массива?
У меня естьпробовал разными способами:
source:"doc['type.keyword'].value=='CHANNEL' ? doc['id'].value == 0 : params.ids.values.contains(doc['id'].value)",
params: {
ids: [5,6]
}
source:"doc['type.keyword'].value=='CHANNEL' ? doc['id'].value == 0 : params.ids.contains(doc['id'].value)",
params: {
ids: ['5','6']
}
source:"doc['type.keyword'].value=='CHANNEL' ? doc['id'].value == 0 : for (el in params.ids) {doc['id'].value==el}",
params: {
ids: ['5','6']
} . ERROR
Единственный способ - без массива, но не помогает мне:
source:"doc['type.keyword'].value=='CHANNEL' ? doc['id'].value == 0 : doc['id'].value==params.ids",
params: {
ids: 5
}
Полный запрос:
searchStr = 'a string' //dynamic
types = ['CHANNEL', 'AUDIO', 'ALBUM', 'MOVIE'] . ///dynamic array of strings
searchAllTypes = ['CHANNEL', 'AUDIO', 'ALBUM', 'MOVIE']
excludedContent = [1, 5, 6, 8] - //a dynamic array
genres = 'aString' //dynamic
tag = 3 //dynamic
query:
{
bool: {
should:
[
//1.here is a function I use, but I added the entire code so it can be read better
return types.map(type => {
type === 'CHANNEL' ? excludedContentIds = [] : excludedContentIds = excludedContents; //2.this is my workaround -
the line I want to get rid of
return {
bool: {
must: [
{ match: { 'type': type } }, //3.if I get rid of line (2) I would use filter - terms - all types here.
//But trying to use terms in combination with 'execution='OR'' is not working inside filters anymore, but inside
query
{ match: { 'discoverable': true } },
{ match: { 'status': 'PUBLISHED' } },
{ match: { 'category.name': genres } },
{ match: { 'tag.id': tag } },
{
multi_match: {
query: searchStr,
type: 'phrase_prefix',
slop: 5,
fields: config.elasticSearch.search.fields,
operator: 'AND',
}
}
],
//// must_not workaround now, because I'm filtering excludedContentIds for CHANNEL in the function above (2)
must_not: [
{ terms: { 'id': excludedContentIds } }
]
}
};
});
]
}
},
aggs: {
'by_top_first': {
terms: {
field: 'type.keyword',
size: searchAllTypes.length,
},
aggs: {
'by_top_hit': { top_hits: { size: 1 } },
'max_score': { max: { script: '_score' } },
}
}
},
{
'by_type': {
terms: {
field: 'type.keyword',
size: searchAllTypes.length
},
aggs: {
'by_top_hit': { top_hits: { size: limitSize ? limitSize : 6 } },
'max_score': { max: { script: '_score' } },
}
}
}