Вложенный запрос в ElasticsearchJAVA

Программисты JAVA общаются здесь
Anonymous
Вложенный запрос в Elasticsearch

Сообщение Anonymous »

В Elasticsearch есть вложенный запрос, и он не работает
Я получил такие данные:

Код: Выделить всё

{
"took": 17,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 6,
"max_score": null,
"hits": [
{
"_index": "candidate",
"_type": "application",
"_id": "4013361",
"_score": null,
"_routing": "64657bb087209b2b37c8f2f2",
"_parent": "64657bb087209b2b37c8f2f2",
"_source": {
"evaluation_records": []
},
"sort": [
1699897664000
]
},
{
"_index": "candidate",
"_type": "application",
"_id": "4005398",
"_score": null,
"_routing": "636b73f187209b293dcd37a3",
"_parent": "636b73f187209b293dcd37a3",
"_source": {
"evaluation_records": []
},
"sort": [
1675245647000
]
},
{
"_index": "candidate",
"_type": "application",
"_id": "4003184",
"_score": null,
"_routing": "6376e71787209b293dcd3917",
"_parent": "6376e71787209b293dcd3917",
"_source": {
"evaluation_records": [
{
"score": 0.0,
"account_id": null,
"create_time": "2023-01-12T11:07:23",
"provider": 4,
"project_id": "133",
"phase_id": 1170,
"project_title": "一个视频题-老",
"project_id_not_analyzed": "133",
"hr_id": 82752,
"status": 1
}
]
},
"sort": [
1673521621000
]
},
{
"_index": "candidate",
"_type": "application",
"_id": "3995775",
"_score": null,
"_routing": "6275e73687209b47703a41ca",
"_parent": "6275e73687209b47703a41ca",
"_source": {
"evaluation_records": []
},
"sort": [
1668000149000
]
},
{
"_index": "candidate",
"_type": "application",
"_id": "3997529",
"_score": null,
"_routing": "63041b6d87209b7edf3d1228",
"_parent": "63041b6d87209b7edf3d1228",
"_source": {
"evaluation_records": [
{
"score": null,
"account_id": null,
"create_time": "2022-09-02T16:19:55",
"provider": 3,
"project_id": "54",
"phase_id": 1170,
"project_title": null,
"project_id_not_analyzed":  "54",
"hr_id": 82752,
"status": 0
}
]
},
"sort": [
1662133365000
]
},
{
"_index": "candidate",
"_type": "application",
"_id": "3996285",
"_score": null,
"_routing": "6255328e87209b47703a410c",
"_parent": "6255328e87209b47703a410c",
"_source": {
"evaluation_records": [
{
"score": 23.2,
"account_id": null,
"create_time": "2022-09-19T15:45:32",
"provider": 3,
"project_id": "54",
"phase_id": 1170,
"project_title": null,
"project_id_not_analyzed": "54",
"hr_id": 82752,
"status": 1
}
]
},
"sort": [
1655291124000
]
}
]
},
"aggregations": {
"CandidateProfileIdAgg": {
"value": 6
}
}
}
когда я использую запрос типа:

Код: Выделить всё

{
"bool": {
"should": {
"bool": {
"should": {
"bool": {
"should": {
"nested": {
"path": "evaluation_records",
"query": {
"bool": {
"must": {
"bool": {
"should": [
{
"bool": {
"must_not": {
"exists": {
"field": "evaluation_records"
}
}
}
},
{
"bool": {
"must": [
{
"exists": {
"field":  "evaluation_records"
}
},
{
"terms": {
"evaluation_records": []
}
}
]
}
}
]
}
}
}
}
}
}
}
}
}
}
}
}
и это не работает. Если я хочу отфильтровать данные, где «записи оценки»: [], что мне делать?
Сопоставление ES следующим образом:
р>

Код: Выделить всё

....
"evaluation_records": {
"type": "nested",
"properties": {
"account_id": {
"type": "long"
},
"create_time": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"hr_id": {
"type": "long"
},
"phase_id": {
"type": "long"
},
"project_id": {
"type": "string"
},
"project_id_not_analyzed": {
"type": "string",
"index": "not_analyzed"
},
"project_title": {
"type": "string",
"index": "not_analyzed"
},
"provider": {
"type": "long"
},
"remark": {
"type": "string",
"index": "not_analyzed"
},
"score": {
"type": "double"
},
"status": {
"type": "long"
}
}
}
...
Требование — отфильтровать записи, которые не были запланированы для оценочных экзаменов.
Проверено множество методов поиска, они не очень хороши.

Подробнее здесь: https://stackoverflow.com/questions/788 ... tic-search

Вернуться в «JAVA»