Elasticsearch Parent / Child. How to query and filter on parent and sort by child field

While I can filter parents with children and sort the answer in the child field, it works like a charm. See below.

GET /parent_child_meta_poc/paren_doc/_search { "query": { "has_child": { "inner_hits": {}, "type": "most_read_doc", "query": { "function_score": { "functions": [ { "field_value_factor": { "factor": 1, "field": "read_count" } } ] } }, "score_mode": "avg" } } } 

Source: Matts gist

Example child display:

 { "mappings": { "most_read_doc": { "_parent": { "type": "paren_doc" }, "properties": { "parent_uri": { "type": "string" }, "read_count": { "type": "long" } } } } } 

However, the restriction applies to such requirements as:

Give me all documents matching these search criteria, return only documents that have children from "most_read_doc", and sort the returned parent documents on the page "most_read_doc.read_count"

Essentially, I would like to:

  • request to the parent document.
  • only parental results that have a child element of "most_read_doc" are returned.
  • sorted by address "most_read_doc.read_count".

Parent / child seems to have fallen by 1. With any type of query, the result of which is "nested: QueryParsingException ... No query for [functions]]" Exception. No official Elasticsearch solution for this is based on my search yet. And I'm struggling to find a working job around this, for now ...

Other similar:

Note I can’t use the attached documents / merge read_count with the parent, as I have two systems applying updates to this index.

  • system x inserts parent documents into the index, overriding any previous document with this identifier, without the possibility of partial updating.
  • system y captures the Google Analytics metadata for most documents read and inserts a child document with an association with the parent through an ID. Thus, system x can continue to insert / replace the parent document without affecting the children.
+5
source share

Source: https://habr.com/ru/post/1257842/


All Articles