Concept "Join: has_child and has_parent queries"

From dataspects::Wiki
C1531830100
Jump to navigation Jump to search





ProblemA:HasSolution::+

For result ProblemA we want to show all solving solutions.

Query Hits
  "_source": {
    "includes": [
      "HasEntityName"
    ],
    "excludes": []
  },
  "query": {
    "bool": {
      "must": {
        "has_child": {
          "type": "annotation",
          "query": {
            "term": {
              "predicate.keyword": {
                "value": "HasSolution"
              }
            }
          },
          "inner_hits": {
            "_source": {
              "includes": [
                "MyType",
                "subject",
                "predicate",
                "objectSOURCE",
                "objectHTML",
                "objectTEXT"
              ],
              "excludes": []
            }
          }
        }
      },
      "filter": {
        "term": {
          "HasEntityName.keyword": {
            "value": "ProblemA"
          }
        }
      }
    }
  }
  "hits": {
    "hits": [
      {
        "_id" : "5d0c9d588080805c587506e0",
        "_source": {
          "HasEntityName": "ProblemA"
        },
        "inner_hits": {
          "annotation": {
            "hits": {
              "hits": [
                {
                  "_source": {
                    "MyType": {
                      "name": "annotation",
                      "parent": "5d0c9d588080805c587506e0"
                    },
                    "subject": "ProblemA",
                    "predicate": "HasSolution",
                    "objectSOURCE": "SolutionA",
                    "objectHTML": "",
                    "objectTEXT": ""
                  }
                }
              ]
            }
          }
        }
      }
    ]
  }
  "_source": {
    "includes": [
      "subject",
      "predicate",
      "objectSOURCE",
      "objectHTML",
      "objectTEXT"
    ],
    "excludes": []
  },
  "query": {
    "bool": {
      "must": {
        "has_parent": {
          "parent_type": "entity",
          "query": {
            "match_all": {}
          },
          "inner_hits": {
            "_source": {
              "includes": [
                "MyType",
                "HasEntityName"
              ],
              "excludes": []
            }
          }
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "predicate.keyword": {
                  "value": "HasSolution"
                }
              }
            },
            {
              "term": {
                "subject": {
                  "value": "problem002"
                }
              }
            }
          ]
        }
      }
    }
  }
  "hits" : {
    "hits" : [
      {
        "_id" : "5d0c9d588080805c587506e5",
        "_source" : {
          "predicate" : "HasSolution",
          "subject" : "Problem002",
          "objectHTML" : "",
          "objectTEXT" : "",
          "objectSOURCE" : "Solution003"
        },
        "inner_hits" : {
          "entity" : {
            "hits" : {
              "hits" : [
                {
                  "_id" : "5d0c9d588080805c587506e0",
                  "_source" : {
                    "MyType" : "entity",
                    "HasEntityName" : "Problem002"
                  }
                }
              ]
            }
          }
        }
      }
    ]
  }

ProblemB:CanCause::ProblemA

For result ProblemA we want to show the causing ProblemB.
  "query": {
    "bool": {
      "must": {
        "has_child": {
          "type": "annotation",
          "query": {
            "bool": {
              "must": [
                {
                  "term": {
                    "predicate.keyword": {
                      "value": "HasSolution"
                    }
                  }
                },
                {
                  "term": {
                    "objectSOURCE": {
                      "value": "solution003"
                    }
                  }
                }
              ]
            }
          },
          "inner_hits": {}
        }
      }
    }
  }