elasticsearch 自制join 插件

这个插件 从 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"
                      ]
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}


 

下载地址 : elasticsearch自制join插件-Java文档类资源-CSDN下载从parent-child修改来的插件,增加了字段join功能更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/qq_25993145/85083221


版权声明:本文为qq_25993145原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。