Я работаю над API на основе NodeJ, и он построен с использованием Elasticsearch и NodeJ.Я должен предоставить функциональность, позволяющую пользователям API исключать некоторый контент на основе условий таксономии.
произвольная форма: Поле с несколькими значениями - тип: строка
игры: поле с несколькими значениями - тип: строка
игроки: поле с несколькими значениями - тип: строка
команды: мультиполе значения - тип: строка
записывающее устройство: поле с несколькими значениями - тип: строка
каналы: поле с несколькими значениями - тип:строка
Формат URL API будет примерно таким, как показано ниже.https://api.test.net/2/xxxxx/article/?exclude=term1+term2
Выше должно возвращать содержимое, которое не помечено для term1 и term2.
Предположим, у нас есть 3 статьи, первая статья помечена как term1, вторая статья помечена как term2 и третьястатья помечена для term1 и term2.
Ожидаемый результат: https://api.test.net/2/xxxxx/article/?exclude=term1+term2 должен возвращать статью первой (помеченную в term1), вторую статью (помеченную в term2), а не третью(Помечено на term1 и term2)
Фактический результат: Иногда https://api.test.net/2/xxxxx/article/?exclude=term1+term2 возвращает все три статьи, а иногда и первую (с тегом term1) и вторую статью (с тегом term2).
Обновление: Ниже приведен правильный документ, и я также добавил запрос, но все еще наблюдаю несоответствие.
Документ:
{
"team":{
"mappings":{
"article":{
"properties":{
"body":{
"properties":{
"content":{
"type":"string"
},
"html":{
"type":"string"
},
"type":{
"type":"string"
}
}
},
"brand":{
"type":"string"
},
"changed":{
"type":"date",
"format":"dateOptionalTime"
},
"changedUtc":{
"type":"long"
},
"content":{
"type":"string"
},
"created":{
"type":"date",
"format":"dateOptionalTime"
},
"createdUtc":{
"type":"long"
},
"domain":{
"type":"string"
},
"headline":{
"type":"string"
},
"langcode":{
"type":"string",
"index":"not_analyzed"
},
"nid":{
"type":"string"
},
"published":{
"type":"date",
"format":"dateOptionalTime"
},
"publishedUtc":{
"type":"long"
},
"raw":{
"type":"string",
"index":"no"
},
"revisionTimestamp":{
"type":"date",
"format":"dateOptionalTime"
},
"revisionTimestampUtc":{
"type":"long"
},
"status":{
"type":"string"
},
"subheadline":{
"type":"string"
},
"syndication":{
"properties":{
"brand":{
"type":"string"
},
"options":{
"properties":{
"actionFrom":{
"type":"string"
},
"publish":{
"type":"string"
},
"status":{
"type":"string"
}
}
},
"type":{
"type":"string"
}
}
},
"taxonomy":{
"properties":{
"coaches":{
"properties":{
"value":{
"type":"string"
}
}
},
"freeform":{
"properties":{
"value":{
"type":"string"
}
}
},
"games":{
"properties":{
"id":{
"type":"string"
},
"value":{
"type":"string"
}
}
},
"players":{
"properties":{
"id":{
"type":"string"
},
"value":{
"type":"string"
}
}
},
"section":{
"properties":{
"value":{
"type":"string"
}
}
},
"teams":{
"properties":{
"city":{
"type":"string"
},
"id":{
"type":"string"
},
"nickname":{
"type":"string"
},
"tricode":{
"type":"string"
},
"urlName":{
"type":"string"
},
"value":{
"type":"string"
}
}
},
"writer":{
"properties":{
"emailAddress":{
"type":"string"
},
"id":{
"type":"string"
},
"responsive_web":{
"type":"string"
},
"title":{
"type":"string"
},
"value":{
"type":"string"
}
}
}
}
},
"teaser":{
"type":"string"
},
"title":{
"type":"string"
},
"type":{
"type":"string"
},
"url":{
"type":"string",
"index":"not_analyzed"
},
"uuid":{
"type":"string",
"index":"not_analyzed"
},
"vid":{
"type":"string"
}
}
}
}
}
}
Запрос:
{
"filter":{
"bool":{
"should":[
[
{
"term":{
"status":1
}
}
]
],
"must":[
]
}
},
"from":0,
"size":10,
"_source":{
"include":[
"uuid",
"nid",
"type",
"title",
"headline",
"shortHeadline",
"teaser",
"url",
"published",
"changed",
"subheadline",
"listImage",
"brand",
"videoId",
"videoSource",
"duration",
"taxonomy",
"includeTerms",
"excludeTerms",
"media",
"credit",
"caption",
"description",
"videoCaptions",
"franchiseId",
"showAirTime",
"slateImage",
"mainImage",
"thumbnailImage",
"showTitle",
"status",
"pubstatus"
]
},
"query":{
"bool":{
"must":[
{
"query_string":{
"query":"langcode:\"en\""
}
},
{
"bool":{
"must_not":{
"query_string":{
"query":"(taxonomy.freeform.value:\"sociosqu\" AND taxonomy.freeform.value:\"nullam\") OR (taxonomy.games.id:\"sociosqu\" AND taxonomy.games.id:\"nullam\") OR (taxonomy.players.id:\"sociosqu\" AND taxonomy.players.id:\"nullam\") OR (taxonomy.teams.id:\"sociosqu\" AND taxonomy.teams.id:\"nullam\") OR (taxonomy.writer.value:\"sociosqu\" AND taxonomy.writer.value:\"nullam\") OR (taxonomy.channels.value:\"sociosqu\" AND taxonomy.channels.value:\"nullam\") OR (taxonomy.section.value:\"sociosqu\" AND taxonomy.section.value:\"nullam\") "
}
}
}
}
]
}
},
"sort":[
{
"publishedUtc":{
"order":"desc"
}
},
{
"_score":{
"order":"desc"
}
}
]
}