使用Firebase进行弹性搜索没有响应?

时间:2019-06-28 12:00:56

标签: node.js elasticsearch google-cloud-functions firebase-tools

我没有从弹性搜索中得到任何响应,它只是返回了这个值,我猜测弹性搜索没有要搜索的数据,可能是因为Firebase和弹性搜索模型在某处有所不同,我不知道任何人都可以帮忙我

{
"took": 1,
"timed_out": false,
"_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
},
"hits": {
    "total": {
        "value": 0,
        "relation": "eq"
    },
    "max_score": null,
    "hits": []
}
}

index.js

const functions = require('firebase-functions');

const request = require('request-promise')

exports.indexPostsToElastic = functions.database.ref('/hostels/{hostel_Id}')
.onWrite(event => {
    let postData = event.data.val();
    let hostel_Id= event.params.hostel_Id;

    console.log('Indexing post:', postData);

    let elasticSearchConfig = functions.config().elasticsearch;
    let elasticSearchUrl = elasticSearchConfig.url + 'hostels/' + hostel_Id;
    let elasticSearchMethod = postData ? 'POST' : 'DELETE';

    let elasticSearchRequest = {
        method: elasticSearchMethod,
        url: elasticSearchUrl,
        auth:{
            username: elasticSearchConfig.username,
            password: elasticSearchConfig.password,
        },
        body: postData,
        json: true
      };

      return request(elasticSearchRequest).then(response => {
         console.log("ElasticSearch response", response);
      });
});

弹性搜索模型

{
"mappings": {

"properties": { 
  "address":    { "type": "text"  }, 
  "price":     { "type": "text"  }, 
  "SEX":      { "type": "text" },  
  "CALL_US":{ "type": "text" },  
  "DESC":{ "type": "text" },  
  "DOUBLE_ROOM_AVAILABLE":{ "type": "integer" },  
  "SINGLE_ROOM_AVAILABLE":      { "type": "integer" },  
  "LOCATION_ID":      { "type": "text" },  
  "NAME":      { "type": "text" },  
  "PICTURES":      { "type": "text" },  
  "SHARING_TYPE":      { "type": "text" },  
  "DOUBLE_ROOM_RENT":      { "type": "text" },  
  "SINGLE_ROOM_RENT": { "type": "text" },

  "amenities":  {

   "properties": { 
   "BATHROOM":    { "type": "text"  }, 
   "CCTV":    { "type": "text"  }, 
   "COMMOM_ROOM":    { "type": "text"  }, 
   "COOLER":    { "type": "text"  }, 
   "LAUNDRY":    { "type": "text"  }, 
   "MESS":    { "type": "text"  }, 
   "PARKING":    { "type": "text"  }, 
   "POWER_BACKUP":    { "type": "text"  }, 
   "REFRIGERATOR":    { "type": "text"  }, 
   "TELIVISON":    { "type": "text"  },
   "WATER_FILTER":    { "type": "text"  },
   "WELL_FURNISHED_ROOM":    { "type": "text"  },
   "WIFI":    { "type": "text"  }
  }
  },

  "bills":{

   "properties": { 
  "ELECTRICITY":{ "type": "text" },
  "MAINTENANCE":{ "type": "text" },
  "MESS":{ "type": "text" } 
  }
  },

  "INSIDE_PICTURES":{

   "properties": { 
  "PIC1":{ "type": "text" },
  "PIC2":{ "type": "text" },
  "PIC3":{ "type": "text" },
  "PIC4":{ "type": "text" },
  "PIC5":{ "type": "text" },
  "PIC6":{ "type": "text" },
  "PIC7":{ "type": "text" },
  "PIC8":{ "type": "text" },
  "PIC9":{ "type": "text" },
  "PIC10":{ "type": "text" }
  }
  },

   "MAP_LOCATION":{

   "properties": { 
  "LATITUDE":{ "type": "integer" },
  "LONGITUDE":{ "type": "integer" }
  }
  },

  "MESS_TIMINGS":{

   "properties": { 
  "BREAKFAST":{ "type": "text" },
  "DINNER":{ "type": "text" },
    "LUNCH":{ "type": "text" }
  }
  }
}
}


}

firebase控制台中的firebase json:

 {
 "hostels": [

{
  "CALL_US": "9785031006",
  "DESC": "qwertyjmnbvdefgbn",
  "DOUBLE_ROOM_AVAILABLE": 0,
  "DOUBLE_ROOM_RENT": "7000",
  "INSIDE_PICTURES": {
    "PIC1": "NULL",
    "PIC10": "NULL",
    "PIC2": "NULL",
    "PIC3": "NULL",
    "PIC4": "NULL",
    "PIC5": "NULL",
    "PIC6": "NULL",
    "PIC7": "NULL",
    "PIC8": "NULL",
    "PIC9": "NULL"
  },
  "LOCATION_ID": "5",
  "MAP_LOCATION": {
    "LATITUDE": 25.144333,
    "LONGITUDE": 75.845583
  },
  "MESS_TIMINGS": {
    "BREAKFAST": "8AM",
    "DINNER": "8PM",
    "LUNCH": "1PM"
  },
  "NAME": "sdfghj",
  "PICTURES": "",
  "SEX": "M",
  "SHARING_TYPE": "1,2",
  "SINGLE_ROOM_AVAILABLE": 1,
  "SINGLE_ROOM_RENT": "6000",
  "address": "xcvgbn",
  "amenities": {
    "BATHROOM": "YES",
    "CCTV": "YES",
    "COMMOM_ROOM": "YES",
    "COOLER": "YES",
    "LAUNDRY": "YES",
    "MESS": "YES",
    "PARKING": "YES",
    "POWER_BACKUP": "YES",
    "REFRIGERATOR": "YES",
    "TELIVISON": "YES",
    "WATER_FILTER": "YES",
    "WELL_FURNISHED_ROOM": "YES",
    "WIFI": "YES"
  },
  "bills": {
    "ELECTRICITY": "10 Rs. per unit",
    "MAINTENANCE": "included in Rent",
    "MESS": "Included in Rent"
  },
  "price": "6000"
}
]
}

任何帮助都将得到

0 个答案:

没有答案