问题
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