elasticsearch 我的弹性贴图中有一个嵌套对象。我正在尝试为该嵌套对象创建筛选查询
正如我所知,当我将对象声明为嵌套时,它创建了一个类似数组的结构来存储该对象类型的多个对象。 这是映射json文件的示例elasticsearch 我的弹性贴图中有一个嵌套对象。我正在尝试为该嵌套对象创建筛选查询,elasticsearch,graphql,kibana,elasticsearch,Graphql,Kibana,正如我所知,当我将对象声明为嵌套时,它创建了一个类似数组的结构来存储该对象类型的多个对象。 这是映射json文件的示例 { "employee": { "dynamic": "strict", "properties": { "id": { "type": "keyword" }, "name": { "type": "keyw
{
"employee": {
"dynamic": "strict",
"properties": {
"id": {
"type": "keyword"
},
"name": {
"type": "keyword"
},
"previous_job_documents": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
"status": {
"type": "keyword"
},
"type": {
"type": "integer"
}
}
}
}}}
从elastic获取的示例数据
"data": {
"nodes": {
"totalCount": 465,
"edges": [
{
"id": "b6ecb8aa-4d12-44d6-8ed7-9ee1003d0d54",
"name": "test",
"previous_job_documents": [
{
"type": "RELIEVING_LETTER",
"status": "NOT_SUBMITTED"
},
{
"type": "OFFER_LETTER",
"status": "SUBMITTED"
},
{
"type": "PAYSLIP_FIRST_MONTH",
"status": "VERIFIED"
},
{
"type": "PAYSLIP_SECOND_MONTH",
"status": "NOT_SUBMITTED"
},
{
"type": "PAYSLIP_THIRD_MONTH",
"status": "NOT_SUBMITTED"
}
]
}
]
}}}
问题:我想写一个过滤器,它会找到所有的员工,他们的名字是test和release\u-LETTER没有提交,OFFER\u-LETTER已经提交
这是我在过滤器中尝试的:
{
"filters": {
"Employee":
{"AND": [{"name": "test"},
{
"path": "previous_job_documents"
"AND": [
{
"term": {
"previous_job_documents.type": {
"value": "RELIEVING_LETTER"
}
}
},
{
"term": {
"previous_job_documents.status": {
"value": "NOT_SUBMITTED"
}
}
},
{
"term": {
"previous_job_documents.type": {
"value": "OFFER_LETTER"
}
}
},
{
"term": {
"previous_job_documents.status": {
"value": "SUBMITTED"
}
}
}
]
}
]
}
}
}
您需要对匹配查询中的嵌套字段使用嵌套查询(因为嵌套字段将单独存储)
{
"query":{
"bool":{
"must":[
{
"match":{"name":"user2"}
},
{
"nested":{
"path": "previous_job_documents",
"query":{
"bool":{
"must":[
{"match": {"previous_job_documents.type": "RELIEVING_LETTER"}},
{"match":{"previous_job_documents.status":"NOT_SUBMITTED"}}
]
}
}
}
},
{
"nested":{
"path": "previous_job_documents",
"query":{
"bool":{
"must":[
{"match": {"previous_job_documents.type": "OFFER_LETTER"}},
{"match":{"previous_job_documents.status":"SUBMITTED"}}
]
}
}
}
}
]
}
}
}