这个插件 从 7.10.3 开发
原理: 内部调用 lucene 的 joinUtil.createJoinQuery(String fromField, boolean multipleValuesPerDocument, String toField, Query fromQuery, IndexSearcher fromSearcher, ScoreMode scoreMode)
附DEMO:
PUT my-index-000006
{
"mappings": {
"properties": {
"my_id": {
"type": "keyword"
},
"question": {
"type": "keyword"
},
"answer": {
"type": "keyword"
},
"info":{
"type": "keyword"
},
"my_join_field": {
"type": "join_plus",
"relations": {
"question": "answer"
}
}
}
}
}
PUT my-index-000006/_doc/1?refresh
{
"my_id": "1",
"question": ["aaa" , "bbb" , "ccc","ddd"],
"info": "This is a question one",
"my_join_field": "question"
}
PUT my-index-000006/_doc/2?refresh
{
"my_id": "2",
"question": "bbb",
"info": "This is a question two",
"my_join_field": "question"
}
PUT my-index-000006/_doc/3?refresh
{
"my_id": "3",
"answer": "aaa",
"info": "This is a answer one",
"my_join_field": "answer"
}
PUT my-index-000006/_doc/4?refresh
{
"my_id": "4",
"answer": "bbb",
"info": "This is a answer two",
"my_join_field": "answer"
}
PUT my-index-000006/_doc/5?refresh
{
"my_id": "5",
"answer": "ddd",
"info": "This is a answer three",
"my_join_field": "answer"
}
GET /my-index-000006/_search
{
"query": {
"has_parent_plus": {
"parent_type": "question",
"query": {
"bool": {
"filter": [
{
"terms": {
"my_id": [
"1"
]
}
}
]
}
}
}
}
}
GET /my-index-000006/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"my_id": "5"
}
},
{
"has_parent_plus": {
"parent_type": "question",
"query": {
"bool": {
"filter": [
{
"terms": {
"my_id": [
"1"
]
}
}
]
}
}
}
}
]
}
}
}