Elasticsearch Java API (eight)--search for subdocuments with the same parent ID

Source: Internet
Author: User

Demand:

Searches for all child documents that have the same parent ID.

Data:

Mapping:

{"      mappings": {        "branch": {},        "employee": {          "_parent": {            "type": "Branch"          }        }      }   }

Parent Document:

{"Index": {"_id": "London"}} {"Name": "London Westminster", "City": "London", "Country": "UK"} {"Index": {"_id": "Liverpool"}} {"Name": "Liverpool Central", "City": "Liverpool", "Country": "UK"} {"Index": {"_id": "Paris"}} {"Name": "Champsélysées", "City": "Paris", "Country": "France"}
Sub-document:

{"Index": {"_id": 1, "parent": "London"}} {"Name": "Alice Smith", "DOB": "1970-10-24", "hobby": "Hiking"} {"Index": {"_id": 2, "parent": "London"}} {"Name": "Mark Thomas", "DOB": "1982-05-16", "hobby": "Diving"} {"Index": {"_id": 3, "parent": "Liverpool"}} {"Name": "Barry Smith", "DOB": "1979-04-01", "hobby": "Hiking"} {"Index": {"_id": 4, "parent": "Paris"}} {"Name": "Adrien Grand", "DOB": "1987-05-11", "hobby": "Horses"}

search for employee with parent ID London:


Curl GET Company/employee/_search
    "Query": {"has_parent": {"         Type": "Branch",         "query": {           "term": {               "_parent": "London"           }         }        }     }}

The search did not result in any results. All sorts of attempts were unsuccessful, and then the answers to the questions on the StackOverflow were answered, and the correct searches were made:



Curl GET Company/employee/_search
{"  query": {"    has_parent": {"      type": "Branch",       "query": {        "IDs": {             "values": ["London" ]        }      }    }  }

The corresponding Java API:

Hasparentquerybuilder hpqb=querybuilders.hasparentquery ("branch", Querybuilders.idsquery (). IDs ("London"));


My question on StackOverflow link: How to search for child documents with the same parent ID in Elasticsearch?

Elasticsearch Java API (eight)--search for subdocuments with the same parent ID

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.