我有一个弹性搜索查询:
{
"query": {
"bool": {
"should": [
{'match_phrase': {'unique_chat_session_id': '1a8905a2-b328-4f57-8ce8-7ba2e43e138e'}}, {'match_phrase': {'unique_chat_session_id': 'f6a83c4a-8d2f-4f04-9eff-e753957fe9d2'}}
]
}
},
"sort": [{"message_no": {"order": "asc"}}]
}
并以以下格式输出:
[
{
'_index': '',
'_type': '',
'_id': 'cPeZLG8BH6c52U24FH95',
'_score': None,
'_source': {
'unique_chat_session_id': '1a8905a2-b328-4f57-8ce8-7ba2e43e138e',
'message_no': 1
},
'sort': [
1
]
},
{
'_index': '',
'_type': '',
'_id': 'dPeZLG8BH6c52U24_X8k',
'_score': None,
'_source': {
'unique_chat_session_id': 'f6a83c4a-8d2f-4f04-9eff-e753957fe9d2',
'message_no': 1
},
'sort': [
1
]
},
{
'_index': '',
'_type': '',
'_id': 'cfeZLG8BH6c52U24FH_x',
'_score': None,
'_source': {
'unique_chat_session_id': '1a8905a2-b328-4f57-8ce8-7ba2e43e138e',
'message_no': 2
},
'sort': [
2
]
},
{
'_index': '',
'_type': '',
'_id': 'dfeZLG8BH6c52U24_X-w',
'_score': None,
'_source': {
'unique_chat_session_id': 'f6a83c4a-8d2f-4f04-9eff-e753957fe9d2',
'message_no': 2
},
'sort': [
2
]
},
{
'_index': '',
'_type': '',
'_id': 'cveZLG8BH6c52U24F3-c',
'_score': None,
'_source': {
'unique_chat_session_id': '1a8905a2-b328-4f57-8ce8-7ba2e43e138e',
'message_no': 3
},
'sort': [
3
]
},
{
'_index': '',
'_type': '',
'_id': 'c_eZLG8BH6c52U24GH8K',
'_score': None,
'_source': {
'unique_chat_session_id': '1a8905a2-b328-4f57-8ce8-7ba2e43e138e',
'message_no': 4
},
'sort': [
4
]
}
]
现在我想进行一个查询,其中我将以数组格式传递 unique_chat_session_id 并精确匹配 [1a8905a2-b328-4f57-8ce8-7ba2e43e138e, f6a83c4a-8d2f-4f04-9eff-e753957fe9d2] 我想在与数组相同的方式。它应该显示第一个数组元素(这里是 1a8905a2-b328-4f57-8ce8-7ba2e43e138e)的所有结果,并在 msg_no 上应用了排序。所以我的输出结果应该是:
[
{
'_index': '',
'_type': '',
'_id': 'cPeZLG8BH6c52U24FH95',
'_score': None,
'_source': {
'unique_chat_session_id': '1a8905a2-b328-4f57-8ce8-7ba2e43e138e',
'message_no': 1
},
'sort': [
1
]
},
{
'_index': '',
'_type': '',
'_id': 'cfeZLG8BH6c52U24FH_x',
'_score': None,
'_source': {
'unique_chat_session_id': '1a8905a2-b328-4f57-8ce8-7ba2e43e138e',
'message_no': 2
},
'sort': [
2
]
},
{
'_index': '',
'_type': '',
'_id': 'cveZLG8BH6c52U24F3-c',
'_score': None,
'_source': {
'unique_chat_session_id': '1a8905a2-b328-4f57-8ce8-7ba2e43e138e',
'message_no': 3
},
'sort': [
3
]
},
{
'_index': '',
'_type': '',
'_id': 'c_eZLG8BH6c52U24GH8K',
'_score': None,
'_source': {
'unique_chat_session_id': '1a8905a2-b328-4f57-8ce8-7ba2e43e138e',
'message_no': 4
},
'sort': [
4
]
}
{
'_index': '',
'_type': '',
'_id': 'dPeZLG8BH6c52U24_X8k',
'_score': None,
'_source': {
'unique_chat_session_id': 'f6a83c4a-8d2f-4f04-9eff-e753957fe9d2',
'message_no': 1
},
'sort': [
1
]
},
{
'_index': '',
'_type': '',
'_id': 'dfeZLG8BH6c52U24_X-w',
'_score': None,
'_source': {
'unique_chat_session_id': 'f6a83c4a-8d2f-4f04-9eff-e753957fe9d2',
'message_no': 2
},
'sort': [
2
]
}
]