lucene - Is it possible to left join nested documents in ElasticSearch queries? -


context

assume have set of documents have defined nested mapping. assume documents have nested documents , not:

document 1

{   "id":1,   "nested":[     {       "x":1     }   ] } 

document 2

{   "id":2,   "nested":[     {       "x":2     }   ] } 

document 3

{   "id":3 } 

problem

is there way perform equivalent of following sql query:

select     r.id,     count(*)     root r     left join     nested n         on parent(n) = r     n.x = 1 /* nested condition */ group     r.id 

something comes close using elasticsearch's query dsl is:

curl -xget http://localhost:9200/nested/type/_search?pretty -d' {    "fields":["id"],    "query":{        "nested":{           "query":{               "constant_score":{                  "query":{                     "term":{"x":1}                  }               },               "boost":1.0            }         },         "path":"nested",         "score_mode":"total"       }    } }' 

however, since semantics of nested queries , nested filters require document have at least 1 nested document, document 3 filtered out here (i.e. "inner-join" semantics).

is there workaround / alternate approach prevent documents being excluded if don't have nested document?


application

to note above condition on nested documents. although simple in example, 1 can imagine situations score based aggregations based on multiple dynamic conditions can not precomputed in advance due combinatorial explosion.

the main value in above query includes results have score value of "0" , preserves global document score sort , can not computed using facets or forthcoming aggregation module.


resources


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -