How query Firebase with ElasticSearch and Flashlight?
<p>When I use Flashlight with Firebase and Elastic search with a straight forward query it does work :</p>

<p><strong>query</strong></p>

<pre><code> {"index":"firebase","query":"rose","type":"tasting"}
</code></pre>

<p><strong>code</strong></p>

<pre><code>...
Map&lt;String,String&gt; q = new HashMap&lt;&gt;();
q.put("index", "firebase");
q.put("type", "tasting");
q.put("query", "rose");

String key = ref.child("request").push().getKey();
ref.child("request").child(key).setValue(q);
...
</code></pre>

<p>But when I want be not limited to only 10 hints, this failed (no results)</p>

<p><strong>query</strong></p>

<pre><code>{"index":"firebase","options":{"from":0,"to":50},"query":{"query_string":{"query":"rose"}},"type":"tasting"}
</code></pre>

<p><strong>code</strong></p>

<pre><code>...
HashMap&lt;String, String&gt; q = new HashMap&lt;&gt;();
q.put("query", "rose");
qs = new HashMap&lt;&gt;();
qs.put("query_string", q);


Map&lt;String, Object&gt; options = new HashMap&lt;&gt;();
options.put("from", 0);
options.put("to", 50);

HashMap&lt;String, Object&gt; qo = new HashMap&lt;&gt;();    
qo.put("index", "firebase");
qo.put("type", "tasting");
qo.put("options", options);
qo.put("query", a);

String key = ref.child("request").push().getKey();
ref.child("request").child(key).setValue(q);
...
</code></pre>

<p>I use the option delivered in the Flashlight example, and add part for option :</p>

<pre><code>"search": {
     "request": {
        "$recid": {
           // I can only read records assigned to me
           ".read": "auth.id === data.child('id').val() || auth.uid === data.child('id').val()",
           // I can only write new records that don't exist yet
           ".write": "!data.exists() &amp;&amp; (newData.child('id').val() === auth.id || newData.child('id').val() === auth.uid)",
           ".validate": "newData.hasChildren(['query', 'index', 'type'])",
           "index": {
              // accepts arrays or strings
              ".validate": "(newData.isString() &amp;&amp; newData.val().length &lt; 1000) || newData.hasChildren()",
              "$child": {
                 ".validate": "newData.isString() &amp;&amp; newData.val().length &lt; 1000"
              }
           },
           "type": {
              // accepts arrays or strings
              ".validate": "(newData.isString() &amp;&amp; newData.val().length &lt; 1000) || newData.hasChildren()",
              "$child": {
                 ".validate": "newData.isString() &amp;&amp; newData.val().length &lt; 1000"
              }
           },
           "query": {
              // structure of the query object is pretty open-ended
              ".validate": "newData.isString() || newData.hasChildren()"
           },
           "$other": {
              ".validate": false
           }
        }
     },
     "response": {
        "$recid": {
           // I can only read/write records assigned to me
           ".read": "auth.id === data.child('id').val() || auth.uid === data.child('id').val()",
           ".write": "auth.id === data.child('id').val() || auth.uid === data.child('id').val()",
           // Assumes that Flashlight will be writing the records using a secret or a token that has admin: true
           // The only thing a logged in user needs to do is delete results after reading them
           ".validate": false
        }
     }
  }
</code></pre>

<p>Why the options parameter can be find at <a href="https://github.com/firebase/flashlight/issues/29#issuecomment-129340229" rel="nofollow">https://github.com/firebase/flashlight/issues/29#issuecomment-129340229</a></p>