elasticsearch:按匹配嵌套文档的值排序

时间:2014-04-03 12:56:09

标签: sorting elasticsearch nested

我选择了嵌套文档来实现多语言书籍搜索,其中包含嵌套文档中doc和edition数据根目录中的常用书籍数据。映射:

{
  "book": {
    "properties": {
      "bookinfo": {
        ...
      },
      "editions": {
        "type": "nested",
        "properties": {
          "editionid": {
            "type": "long",
            "store": "yes",
            "index": "no"
          },
          "title_author": {
            "type": "string",
            "store": "no",
            "index": "analyzed"
          },
          "title": {
            "type": "string",
            "store": "yes",
            "index": "not_analyzed"
          },
          "languageid": {
            "type": "short",
            "store": "yes",
            "index": "no"
          },
          "ratings": {
            "type": "integer",
            "store": "no"
          }
        }
      }
    }
  }
}

一本书的不同版本包含在嵌套文档中 - 可以是不同的语言,但也可以是不同的发布者,isbn等。有时甚至标题也与同一语言的版本不同。

搜索文档时(在title_author字段上)我需要知道其他嵌套的doc信息,例如languageid和rating,以根据用户的语言技能和版本的相关性来提高匹配分数。

我没有将每个版本都放在单独的文档中的原因是我只希望每本书有一个匹配(最匹配的一个)。并且ElasticSearch没有UNIQUE功能。我需要分页。因此,每当我在查询内部使用双书后更改结果集时,ElasticSearch的分页就会中断。

嵌套排序功能似乎对此没有帮助,因为它对一本书的所有嵌套文档进行排序。

如何访问匹配的嵌套文档的信息?

如果这无法实现,我怎么能通过多重搜索来解决这个问题?

1 个答案:

答案 0 :(得分:0)

要访问嵌套文档字段,您可以使用:

doc['editions. languageid'].value

对于提升部分,请尝试一些示例:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html

这就是你要找的东西吗?