简体   繁体   中英

Elastic Search Indexing in php

I have a codeigniter application where I try to set up elasticsearch, I have my json which looks like this:

    {
    "took": 4,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 1.0,
        "hits": [
            {
                "_index": "features",
                "_type": "liste",
                "_id": "test",
                "_score": 1.0,
                "_source": {
                    "mnuActiveSection": "securite.features",
                    "rowsFeatures": [
                        {
                            "id": "50",
                            "idCategory": "5",
                            "Name": "01- Data",
                            "FeatureCategory": "Serie",
                            "NombrePrivileges": "9",
                            "ListePrivileges": "Admin"
                        },
                        {
                            "id": "51",
                            "idCategory": "5",
                            "Name": "02- Data 2",
                            "FeatureCategory": "Documentary",
                            "NombrePrivileges": "3",
                            "ListePrivileges": "Direction"
                        },
                        {
                            "id": "52",
                            "idCategory": "5",
                            "Name": "03- Data 3",
                            "FeatureCategory": "Films",
                            "NombrePrivileges": "7",
                            "ListePrivileges": "Super Admin"
                        }
                    ]
                }
            }
        ]
    }
}

I would like to display the list of features in my view, and to search the documents via elastic search. unfortunately I can not display the data json.

This is not what I will like, because I have the impression that I have all my data grouped in a single object array. To be done I try to use a "foreach" but unfortunately I do not get what I'm looking for. I am stuck at this stage. I would like for each data of my table to have a different _id for example to better visualize them.

public function liste()
{

    $data["mnuActiveSection"] = "securite.features";

    $Finder = new FeaturesFinder();
    $data["rowsFeatures"] = $Finder->FindAll();
    $this->load->library('elasticsearch');

    foreach($data["rowsFeatures"] as $d){
        $this->elasticsearch->index = 'features';
        $this->elasticsearch->create();
        $this->elasticsearch->add($type ='liste',$id = 'test',$data);
        var_dump($d);  
    }
}

If anyone could help me find a track I'm interested.

thank you very much

I think what you're trying to do is this:

$i = 0;
    foreach($data["rowsFeatures"] as $d){
        $i++;
        $this->elasticsearch->index = 'features';
        $this->elasticsearch->create();
        $this->elasticsearch->add($type ='liste',$id = $i,$data);
        var_dump($d);  
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM