How to indexing all the data Elasticsearch

Discussion in 'PHP' started by TeFoN, Feb 9, 2015.

  1. #2
    I use MongoDB and Elasticsearch. I want indexing elasticsearch my all data in MongoDB.

    My MongoDB collection:
     {
       "_id": ObjectId("54d8e4bd5f758c461e8b4568"),
       "name": "iPod Touch, iPhone, iPad Dokunmatik Kalem",
       "urlname": "ipod-touch-iphone-ipad-dokunmatik-kalem",
       "price": "21,78",
       "price_for_filter": 21,
       "image": "2015\/02\/ipod-touch-iphone-ipad-dokunmatik-kalem-1122968264.jpg",
       "description": "En uygun fiyat ve taksit seçenekleri ile iPod Touch, iPhone, iPad Dokunmatik Kalem Ereyon'da",
       "keywords": "..",
       "url": "http:\/\/www.ereyon.com.tr\/store\/productdetails.aspx?productid=10148385",
       "sitemap_id": NumberLong(221),
       "shop_id": NumberLong(19),
       "logo": "",
       "key": "9f90e7805fa396b23c39daf538844e77",
       "type": NumberLong(1),
       "shop_rating_count": NumberLong(0),
       "shop_rating_point": NumberLong(0),
       "created_at": "2015-02-09 16:47:57",
       "updated_at": "2015-02-09 16:47:57"
    }   
    
    Code (JavaScript):
    My index function for Elasticsearch
                            $data = array("name"=>HelperMC::strToUtf8(trim($name)),
                                          "urlname"=>HelperURL::strToURL(trim($name)),
                                           "price"=>HelperParser::clearTextFromPrice($price),
                                           "price_for_filter"=>floatval(HelperParser::clearTextFromPrice($price)),
                                           "image"=>$imgname,
                                           "description"=>HelperMC::strToUtf8($description),
                                           "keywords"=>HelperMC::strToUtf8($keywords),
                                           "url"=>$k['url'],
                                           "sitemap_id"=>intval($sitemapId),
                                           "shop_id"=>$shop['shop_id'],
                                           "logo"=>$shop['logo'],
                                           "key"=>$hashKey,
                                           "type"=>intval(1),
                                           "shop_rating_count"=>intval($shop['rating_count']),
                                           "shop_rating_point"=>intval($shop['rating_point']),
                                           "created_at"=>date("Y-m-d H:i:s"),
                                           "updated_at"=>date("Y-m-d H:i:s"));
    
    
                            //create elasticsearch index
                            HelperES::insertEntry(json_encode($data),$hashKey);
    PHP:
    and finally, my insertEntry function in HelperES
        public static function insertEntry($data_string,$id = false){
            if($id)
                $url = self::$elasticBase."/".$id;
            else
                $url = self::$elasticBase;
    
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL , $url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            @$result = curl_exec($ch);
            curl_close($ch);
    
            return $result;
        }
    PHP:
    I want receive "name, urlname, price, .............. ,created_at, updated_at" in mongodb and sending elasticsearch for all items.

    Is there a practical solution?
     
    TeFoN, Feb 9, 2015 IP
  2. TeFoN

    TeFoN Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    any idea?
     
    TeFoN, Feb 10, 2015 IP