Когда я использую Flashlight с поиском Firebase и Elastic с прямым запросом, он работает:
запрос
{"index":"firebase","query":"rose","type":"tasting"}
код
...
Map<String,String> q = new HashMap<>();
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);
...
Но когда я хочу не ограничиваться только 10 подсказками, это не удалось (без результатов)
запрос
{"index":"firebase","options":{"from":0,"to":50},"query":{"query_string":{"query":"rose"}},"type":"tasting"}
код
...
HashMap<String, String> q = new HashMap<>();
q.put("query", "rose");
qs = new HashMap<>();
qs.put("query_string", q);
Map<String, Object> options = new HashMap<>();
options.put("from", 0);
options.put("to", 50);
HashMap<String, Object> qo = new HashMap<>();
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);
...
Я использую опцию, предоставленную в примере с фонариком, и добавляю часть для опции:
"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() && (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() && newData.val().length < 1000) || newData.hasChildren()",
"$child": {
".validate": "newData.isString() && newData.val().length < 1000"
}
},
"type": {
// accepts arrays or strings
".validate": "(newData.isString() && newData.val().length < 1000) || newData.hasChildren()",
"$child": {
".validate": "newData.isString() && newData.val().length < 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
}
}
}
Почему параметр options можно найти по адресу https://github.com/firebase/flashlight/issues/29#issuecomment-129340229