Skip to content
This repository has been archived by the owner on Mar 4, 2019. It is now read-only.

Direct JSON Query similar to Model::query #17

Closed
derekperkins opened this issue Nov 22, 2013 · 1 comment
Closed

Direct JSON Query similar to Model::query #17

derekperkins opened this issue Nov 22, 2013 · 1 comment

Comments

@derekperkins
Copy link
Contributor

I have a complex query (see below) that works using cURL, but I don't know how to form the syntax so that the datasource can interpret it.

{
  "query": {
    "has_child": {
      "type": "workspaces_posts_tags",
      "query" : {
        "filtered": {
          "query": { "match_all": {}},
          "filter" : {
            "and": [
              {"term": {"workspace_id": 2}},
              {"term": {"post_id": 4}}
            ]
          }
        }
      }
    }
  }
}

I tried setting $query to this in the beforeFind in a custom find method, but it didn't like it. It also didn't give any meaningful errors.

$query = [
    'conditions' => [
        'has_child' => [
            'type' => 'workspaces_posts_tags',
            'query' => [
                'filtered' => [
                    'query' => [
                        'match_all' => []
                    ],
                    "filter" => [
                        'and' => [
                            'term' => [
                                'workspace_id' => 2
                            ],
                            'term' => [
                                'post_id' => 4
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]
];

My thoughts are that it might be nice to have a method available where I could pass in a JSON formatted query and use that as the query. Is there a way to do that? If not, do you know how I should format the query properly for this plugin?

@CriztianiX
Copy link
Contributor

You can use my fork. I have implemented this functionality.

Example:

$query = [
'size' => 1,
'query' => [
'match_all' => []
]
];

    debug($this->ClientContact->query($query));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants