与嵌套对象查询Elasticsearch

问题描述 投票:2回答:1

我有一个嵌套映射的索引。我想大跳查询,将返回以下内容:给我所有的文件在哪里搜索词的每个词出现在一个或多个嵌套的文件。

这是该指数:

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"
              }
            }
          }
        }
      }
    }

我想预制棒查询是,如果我搜索“我的名字是帅哥”,并给所有的地方所有的话都发现文件 - 可能是在嵌套的文档,可能在名称字段。例如,我可以用在嵌套文件在名称字段中的值“家伙”等字样的文件

elasticsearch nested
1个回答
0
投票

为了做到这一点,我通常分裂的条款和产生这样的请求(FOO:棒是上的其他领域中的其他条件):

{
  "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"
          }
        }
      }
    ]
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.