elasticsearch - Can I specify a fallback preference for a "should" query? -


if have 2 documents in index, locale values en , pt,

{   "slug": "my-object",   "locale": "en", }  {   "slug": "my-object",   "locale": "pt", } 

and run query result should in locale don't have, fr,

{   "query": {     "bool": {       "must":  [{ "term": { "slug":   "my-object" } }],       "should":[{ "term": { "locale": "fr" } }]     }   },   "size": 1 } 

is there way make fall doc en locale, not pt or other?

basically, want "it should in french, accept english."

good news! looks recent updates slated 1.3 release should allow work in general case (more 1 result, supporting pagination). isn't in form of "should" query, though, called top_hits aggregator:

https://github.com/elasticsearch/elasticsearch/pull/6124 https://github.com/elasticsearch/elasticsearch/issues/6299

if need 1 response or known small response set applying logic client side easiest way going least amount of effort. so, should "en", "fr" , ignore en if fr comes back.

another option modeling data such further denormalize things. therefore, including variants of slug within same document may simplify things. add other complications, ymmv.


Comments

Popular posts from this blog

C# random value from dictionary and tuple -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -