【发布时间】:2018-12-23 15:04:34
【问题描述】:
我有一个带有嵌套映射的索引。 我想执行一个查询,该查询将返回以下内容:给我搜索词中的每个单词出现在一个或多个嵌套文档中的所有文档。
这是索引:
properties: {
column_values_index_as_objects: {
type: "nested",
properties: {
value: {
ignore_above: 256,
type: 'keyword',
fields: {
word_middle: {
analyzer: "searchkick_word_middle_index",
type: "text"
},
analyzed: {
term_vector: "with_positions_offsets",
type: "text"
}
}
}
}
}
}
这是我尝试的最新查询:
nested: {
path: "column_values_index_as_objects",
query: {
bool: {
must: [
{
match: {
"column_values_index_as_objects.value.analyzed": {
query: search_term,
boost: 10 * boost_factor,
operator: "or",
analyzer: "searchkick_search"
}
}
}
例如,如果我搜索单词“食物和水”,我希望每个单词至少出现在嵌套文档中。 即使只存在一个单词,当前搜索也会返回文档
感谢您的帮助!
更新: 正如 Cristoph 建议的那样,该解决方案有效。现在我有以下问题。
这是我的索引:
properties: {
name: {
type: "text"
},
column_values_index_as_objects: {
type: "nested",
properties: {
value: {
ignore_above: 256,
type: 'keyword',
fields: {
word_middle: {
analyzer: "searchkick_word_middle_index",
type: "text"
},
analyzed: {
term_vector: "with_positions_offsets",
type: "text"
}
}
}
}
}
}
我想要执行的查询是如果我搜索“我的名字是家伙”,并且会给出所有找到所有单词的文档 - 可能在嵌套文档中,也可能在名称字段中。 例如,我可以有一个文档,其中 name 字段的值为“guy”,嵌套文档中的其他单词
【问题讨论】:
-
如果你想要 AND 的话,那么操作符的值应该是
and而不是or。 -
谢谢!如果我使用“AND”,这意味着只有当整个句子都在值中时它才会给我结果。这不是我想要的。我希望每个单词都会出现在至少一个子文档中
标签: elasticsearch nested