0

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

3
  • To clarify, what exactly are you trying to do here? What is your intended output from your program?
    – CEH
    Commented Oct 7, 2019 at 17:33
  • the expected result is to be able 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
    – Dax
    Commented Oct 7, 2019 at 17:43

1 Answer 1

0

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);  
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.