首页 > 解决方案 > 我可以在嵌套字段中为弹性搜索中的不同块使用 spannear 吗?

问题描述

该文件是这样的:

doc = {  
  "id": 1,  
  "content": [  
    {  
      "txt": I,  
      "time": 0,  
    },  
    {  
      "txt": have bla bla,  
      "time": 1,  
    },  
    {  
      "txt": bla bla book,  
      "time": 2,  
    },  
    {  
      "txt": do not match this block,  
      "time": 3,  
    },  
  ]  
}  

搜索查询是这样的:

"span_near": {
    "clauses": [
        {"span_term": {"content.txt": "I"}},
        {"span_term": {"content.txt": "book"}},
    ],
    "slop": 5,
    "in_order": False,
}

我想返回 "content.time": [0,1,2]

现在,我知道通过使用嵌套字段,可以检索“content.time”,但似乎“content.txt”在每个块之间是分开的。我想像扁平结构一样搜索整个“content.txt”,但仍然可以返回匹配的“content.time”。有谁知道如何实现这一目标?谢谢!

标签: elasticsearchsearch-engine

解决方案


推荐阅读