[英]Elasticsearch with nested objects query
我有一個帶有嵌套映射的索引。 我想執行一個查詢,該查詢將返回以下內容:給我所有文檔,其中搜索詞中的每個單詞都出現在一個或多個嵌套文檔中。
這是索引:
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"
}
}
}
例如,如果我搜索“食品和水”一詞,我希望每個詞至少出現在嵌套文檔中。 即使只有一個單詞,當前搜索也會返回文檔
謝謝您的幫助!
更新:正如克里斯托弗建議的那樣,該解決方案有效。 現在我有以下問題。
這是我的索引:
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"
}
}
}
}
}
}
我要執行的查詢是,如果我搜索“我的名字是男的”,並將給出所有單詞都找到的所有文檔-可能在嵌套文檔中,也可能在名稱字段中。 例如,我可能在名稱字段中有一個值為“ guy”的文檔,而在嵌套文檔中有其他單詞
為了做到這一點,我通常會拆分條款並生成這樣的請求(foo:bar是另一個字段上的另一個條件):
{
"bool": {
"must": [
{
"nested": {
"path": "column_values_index_as_objects",
"query": {
"match": {
"column_values_index_as_objects.value.analyzed": {
"query": "food",
"boost": "10 * boost_factor",
"analyzer": "searchkick_search"
}
}
}
}
},
{
"nested": {
"path": "column_values_index_as_objects",
"query": {
"match": {
"column_values_index_as_objects.value.analyzed": {
"query": "and",
"boost": "10 * boost_factor",
"analyzer": "searchkick_search"
}
}
}
}
},
{
"nested": {
"path": "column_values_index_as_objects",
"query": {
"match": {
"column_values_index_as_objects.value.analyzed": {
"query": "water",
"boost": "10 * boost_factor",
"analyzer": "searchkick_search"
}
}
}
}
},
{
"query": {
"term": {
"foo": "bar"
}
}
}
]
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.