ElasticSearch - 嵌套字段的全文搜索

时间:2016-04-14 10:26:55

标签: elasticsearch

如果有人可以提供帮助?     1.全文搜索查询,其中标题和描述都是顶级字段

GET /docidx/Document/_search
{
    "query": {
        "query_string": {
            "query": "title:computer AND description:electronics"
        }
     }
}

This works fine.

2. The full text search query where title is top level field but "abstract.content" i.e content is a nested field under abstract - does not return results.

GET /docidx/Document/_search
{
  "query": {
       "query_string": {
          "query": "title:computer AND abstract.content:memory"
        }
    }
}

Does Elastic Search has support for full text search for nested fields?

1 个答案:

答案 0 :(得分:0)

使用mustnested Query的组合:

GET /docidx/Document/_search
{
"query": {
  "bool": {
     "must": [
        {
           "query_string": {
              "default_field": "title",
              "query": "computer"
           }
        },
        {
           "nested": {
              "path": "abstract",
              "query": {
                 "query_string": {
                    "default_field": "abstract.content",
                    "query": "memory"
                 }
              }
           }
          }
       ]
       }
    }
  }