2016-10-24 13 views
11

Tôi đang cố gắng tích hợp FireSearch wit Firebase. Tôi đang sử dụng Flashlight integration từ Firebase để thiết lập tất cả. Tôi đã triển khai mã để Heroku như mô tả trong repo Github liên kết ở trên.Không thể thực hiện theo dõi hoặc truy vấn đường dẫn phù hợp với Firebase và ElasticSearch (bằng Đèn pin)

Nó hoạt động theo nghĩa khi tôi chèn truy vấn objet vào /search/request/ Tôi nhận được kết quả /search/response. Nhưng kết quả là một chút lộn xộn, không chính xác. Nhưng tôi không thể tìm ra điều gì sai.

Đây là những gì được quy định tại config.js nơi tôi xác định con đường để theo dõi:

/** Paths to Monitor 
* 
* Each path can have these keys: 
* {string} path: [required] the Firebase path to be monitored, for example, `users/profiles` 
*      would monitor https://<instance>.firebaseio.com/users/profiles 
* {string} index: [required] the name of the ES index to write data into 
* {string} type: [required] name of the ES object type this document will be stored as 
* {Array} fields: list of fields to be monitored and indexed (defaults to all fields, ignored if "parser" is specified) 
* {Array} omit: list of fields that should not be indexed in ES (ignored if "parser" is specified) 
* {Function} filter: if provided, only records that return true are indexed 
* {Function} parser: if provided, the results of this function are passed to ES, rather than the raw data (fields is ignored if this is used) 
* 
* To store your paths dynamically, rather than specifying them all here, you can store them in Firebase. 
* Format each path object with the same keys described above, and store the array of paths at whatever 
* location you specified in the FB_PATHS variable. Be sure to restrict that data in your Security Rules. 
****************************************************/ 

exports.paths = [{ 
    path: "users", 
    index: "firebase", 
    type: "user" 
}, { 
    path: "messages", 
    index: "firebase", 
    type: "message", 
    fields: ['msg', 'name'], 
    filter: function(data) { 
     return data.name !== 'system'; 
    } 
}]; 

Đây là cấu trúc của nút sử dụng trong căn cứ hỏa lực (nó nằm ở thư mục gốc).

"users" : { 
    "userid123" : { 
     "friends" : { 
     "userid42" : 1 
     }, 
     "recs" : { 
     "-recid1234" : 0 
     }, 
     "user_info" : { 
     "createdAt" : 1475157596, 
     "email" : "[email protected]", 
     "name" : "Firstname Lastname Johnson", 
     "profilePicture" : "png.jpg", 
     "pushId" : { 
     }, 
     "username" : "userLooser" 
     } 
    }, 
    "userid42" : { 
     "friends" : { 
     "userid123" : 1, 
     "test1" : 1 
     }, 
     "recs" : { 
     "-recid5678" : 0 
     }, 
     "user_info" : { 
     "email" : "[email protected]", 
     "name" : "Firstname Lastname", 
     "phoneNumber" : "", 
     "profilePicture" : "jpg.png", 
     "pushId" : { 

     }, 
     "username" : "userName" 
     } 
    } 
    } 
} 

Điều tôi muốn đạt được là tìm kiếm tên người dùng và trả lại kết quả hàng đầu. Tất cả tôi thực sự cần trở lại là tên người dùng và id người dùng.

Image of firebase search query

Nhưng tôi nhận được câu trả lời dưới đây, khi tôi truy vấn với các đối tượng trong hình trên:

"search" : { 
    "response" : { 
     "index" : { 
     ".priority" : 1.477326417519E12, 
     "hits" : [ { 
      "_id" : "test1", 
      "_index" : "firebase", 
      "_score" : 1, 
      "_source" : { 
      "friends" : { 
       "test1" : 1 
      }, 
      "recs" : { 
      }, 
      "user_info" : { 
       "createdAt" : 1475157596, 
       "name" : "Testbruker 1", 
       "username" : "testuzer" 
      } 
      }, 
      "_type" : "user" 
     }, { 
      "_id" : "userid123", 
      "_index" : "firebase", 
      "_score" : 1, 
      "_source" : { 
      "friends" : { 
      }, 
      "recs" : { 

      }, 
      "user_info" : { 
       "email" : "", 
       "name" : "Firstname Lastname", 
       "phoneNumber" : "", 
       "profilePicture" : "", 
       "pushId" : { 
       }, 
       "username" : "profileName" 
      } 
      }, 
      "_type" : "user" 
     }, { 
      "_id" : "userid42", 
      "_index" : "firebase", 
      "_score" : 1, 
      "_source" : { 
      "friends" : { 
      }, 
      "recs" : { 

      }, 
      "user_info" : { 
       "createdAt" : 1475157596, 
       "email" : "[email protected]", 
       "name" : "Firstname Lastname Johnson", 
       "profilePicture" : "", 
       "pushId" : { 
       }, 
       "username" : "userLooser" 
      } 
      }, 
      "_type" : "user" 
     } ], 
     "max_score" : 1, 
     "total" : 3 
     }, 
     "query" : { 
     ".priority" : 1.477326417484E12, 
     "hits" : [ { 
      "_id" : "test1", 
      "_index" : "firebase", 
      "_score" : 1, 
      "_source" : { 
      "friends" : { 
       "test1" : 1 
      }, 
      "recs" : { 
      }, 
      "user_info" : { 
       "createdAt" : 1475157596, 
       "name" : "Testbruker 1", 
       "username" : "testuzer" 
      } 
      }, 
      "_type" : "user" 
     }, { 
      "_id" : "userid42", 
      "_index" : "firebase", 
      "_score" : 1, 
      "_source" : { 
      "friends" : { 

      }, 
      "recs" : { 

      }, 
      "user_info" : { 
       "email" : "", 
       "name" : "Firstname Lastname", 
       "phoneNumber" : "", 
       "profilePicture" : "", 
       "pushId" : { 

       }, 
       "username" : "profileName" 
      } 
      }, 
      "_type" : "user" 
     }, { 
      "_id" : "userid123", 
      "_index" : "firebase", 
      "_score" : 1, 
      "_source" : { 
      "friends" : { 
      }, 
      "recs" : { 

      }, 
      "user_info" : { 
       "createdAt" : 1475157596, 
       "email" : "[email protected]", 
       "name" : "Firstname Lastname Johnson", 
       "profilePicture" : "", 
       "pushId" : { 

       }, 
       "username" : "userLooser" 
      } 
      }, 
      "_type" : "user" 
     } ], 
     "max_score" : 1, 
     "total" : 3 
     }, 
     "type" : { 
     ".priority" : 1.477326417503E12, 
     "hits" : [ { 
      "_id" : "test1", 
      "_index" : "firebase", 
      "_score" : 1, 
      "_source" : { 
      "friends" : { 
       "test1" : 1 
      }, 
      "recs" : { 
      }, 
      "user_info" : { 
       "createdAt" : 1475157596, 
       "name" : "Testbruker 1", 
       "username" : "testuzer" 
      } 
      }, 
      "_type" : "user" 
     }, { 
      "_id" : "userid42", 
      // Same content as above 
     }, { 
      "_id" : "userid123", 
      // Same content as above 
     } ], 
     "max_score" : 1, 
     "total" : 3 
     } 
    } 
    } 

nào:

  • A) Không trả lại sắp xếp chính xác. Kết quả đầu tiên không phù hợp với truy vấn tìm kiếm của tôi chút nào, có vẻ như nó trả về tất cả người dùng theo thứ tự ngẫu nhiên.
  • B) Phản hồi thực sự lộn xộn. dưới /response có ba nút query, typeindex tất cả chứa nhiều lần truy cập.

Vì vậy, bất kỳ ai biết điều gì là sai? Làm thế nào tôi có thể tạo một truy vấn, hoặc thủ công giám sát đường dẫn để tìm kiếm sẽ hoạt động? Và có thể nhận được phản hồi đơn giản hơn?

Trả lời

5

Đèn pin thực sự tìm kiếm các yêu cầu tại phím tìm kiếm/yêu cầu/$, cần chứa tài liệu có loại trường, chỉ mục, truy vấn. Nó đặt một phản ứng tại khóa tìm kiếm/phản hồi/$ với kết quả. Nếu bạn muốn kiểm tra bằng cách thêm thủ công các khóa, hãy thử đặt yêu cầu dưới một nút khác, ví dụ: tìm kiếm/yêu cầu/testkey123.

+0

Nhìn vào đó! Đó là một giải pháp đơn giản cho một thứ mà tôi đã phải vật lộn trong một thời gian dài. Cảm ơn bạn. Nên có một cái gì đó về điều này trong tài liệu đèn pin. – eivindml

0

Tôi tryed everthing và sau giờ cố gắng tôi phát hiện ra:

Trong tập tin của tôi .config của Đèn pin dự án, tôi thiết lập:

exports.paths = [ 
    { 
    path : "albuns", 
    index: "firebase", 
    type : "album", 
    fields: ['nome'] 
    } 
]; 

Bây giờ, bạn cần gửi cuộc gọi http PUT cho căn cứ hỏa lực <URL_PROJECT>/search/request/<ID_CREATED_FOR_YOU>.json (sử dụng ứng dụng/json), bạn có thể kiểm tra nó bằng cách sử dụng Postman Extension, các cơ thể ở lại:

{ 
    "index": "firebase", 
    "type": "album", 
    "q": "John*" 
} 
Các vấn đề liên quan