Can I use spannear in the nested field for different block in elasticsearch?

心不动则不痛 提交于 2021-02-11 13:01:44

问题


The document is like:

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,  
    },  
  ]  
}  

And the search query is like:

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

And I want to return "content.time": [0,1,2]

Now, I know by using the nested field, the "content.time" can be retrieved, but it seems like the "content.txt" is separated between each block. And I want to search for the entire "content.txt" like a flattened structure, but still can return the matching "content.time". Is there anyone know how to achieve this? Thank you!

来源:https://stackoverflow.com/questions/64762234/can-i-use-spannear-in-the-nested-field-for-different-block-in-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!