2016-09-27 2 views
1

내가 사용하고 Flashlight Firebase 플러그인중포 기지 손전등 (ElasticSearch) 필터링, 정렬, 페이지 매김

나는이 example을 사용하고 있으며이 예에서 잘

을 작동하고 당신이 example.js 파일을 볼 수는 쿼리에 대한 방법을 I는 JSO 을 다음과 같은 값을 전달할 때, 상기 기능

// display search results 
    function doSearch(index, type, query) { 

     var ref = database.ref().child(PATH); 
     var key = ref.child('request').push({ index: index, type: type, query: query } ).key; 
     ref.child('response/'+key).on('value', showResults); 

    } 

아래 나에게 결과를 반환 내가 나에게 결과

http://localhost:9200/firebase/user/_search?q=*mani*&pretty&size=5&from=1 

를 반환 JSON

{ index: index, type: type, query: { "from" : 1, "size" : 5 , "query": query } 

을 다음과 같이 값을 전달하려고 노력하지만 ElasticSearch API을 다음입니다 때 N

{ index: index, type: type, query: query } 

것은 나에게 아무 것도 반환하지 않습니다 및 다음과 같이 손전등을 사용하여 쿼리를 필터링하는 방법

{ 
"rules": { 

    ".read": false, 
    ".write": false, 
    "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 
     } 
    } 
    } 
} 
} 

날 손전등 마지막으로 내가 나 자신 여기

했다

답변

0

복잡한 쿼리 및 필터링을 수행하는 방법을 알려 주시기 바랍니다 내가 사용하고 보안 규칙에 따라

{ 
    "query": { 
    "filtered": { 
     "query": { 
      "query_string": { 
       "query": "drama" 
      } 
     }, 
     "filter": { 
      //Filter to apply to the query 
     } 
    } 
    } 
} 

는 솔루션입니다

를 업데이트해야합니다.3210

_process: function (snap) { 
    var dat = snap.val(); 
    var key = snap.key; 

    if (this._assertValidSearch(key, dat)) { 

     // get your query string 

    var q = dat.query.query; 
    console.log('search', "test", JSON.stringify(dat, null, 2)); 
    // build your ES query 
    //var q1 = {"query":{"match":{"_all":q}}}; 
     // Perform (a very simple) ElasticSearch query 
     this.esc.search({ 
      index: dat.index, 
      type: dat.type, 
      // add options 
      from : dat.query.from, 
      size : dat.query.size, 
      // add ES Query 
      //body : q1 
      q:dat.query.query 
     }, function (error, response) { 
      if (error) { 
       this._reply(key, {error: error, total: 0}); 
      } else { 
       this._reply(key, response); 
      } 
     }.bind(this)); 
    } 
} 

및 업데이트 Example.js

// display search results 
    function doSearch(index, type, query) { 
     var ref = database.ref().child(PATH); 
     var jsonOBJ = { 
     index: index, 
     type: type, 
     query: { size:1, from:0, query:query}, 
     }; 
     var key = ref.child('request').push(jsonOBJ).key; 
     console.log('search', key, JSON.stringify(jsonOBJ, null, 2)); 
    ref.child('response/'+key).on('value', showResults); 
    }