Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get mapping of alias with ES1.1 #588

Closed
mal opened this issue Apr 17, 2014 · 6 comments
Closed

Cannot get mapping of alias with ES1.1 #588

mal opened this issue Apr 17, 2014 · 6 comments

Comments

@mal
Copy link
Contributor

mal commented Apr 17, 2014

The real index name now forms part of the mapping response. This is a problem because the current getMapping function uses the name of the Index being queried as the key to look for in the response. An example of this can be seen in Type.php#L301 however I believe the same problem exists in Index.php and possibly in other places.

Example

A real index named "foo".
An alias of that index named "bar".

$c = new Client();
$c->getIndex('foo')->getMapping(); // returns correct mapping
$c->getIndex('bar')->getMapping(); // returns empty array
ruflin added a commit that referenced this issue Apr 19, 2014
@ruflin
Copy link
Owner

ruflin commented Apr 19, 2014

Should be fixed with this commit: 0b410cd

@ruflin ruflin closed this as completed Apr 19, 2014
@mal
Copy link
Contributor Author

mal commented Apr 20, 2014

That looks good for fixing the issue in Index.php but I think (although I've not had a chance to test it) that it will still exist in Type.php#L301.

I'm relatively new to Elastica, so I'm not sure what the result of a Type::getMapping call should be, but if it's intended to be basically the same as the argument passed to Type::setMapping then I think it also needs to drill into the results using the Type's name, maybe something like?

    public function getMapping()
    {
        $path = '_mapping';

        $response = $this->request($path, Request::GET);
        $data = $response->getData();

        $mapping = array_shift($data);
        if (isset($mapping['mappings'][$this->getName()]['properties'])) {
            return $mapping['mappings'][$this->getName()]['properties'];
        }

        return array();
    }

@ruflin ruflin reopened this Apr 20, 2014
@ruflin
Copy link
Owner

ruflin commented Apr 20, 2014

I assume you are right so I reopened the issue. Can you open a pull request with the above?

@mal
Copy link
Contributor Author

mal commented Apr 20, 2014

Happy to do so, but I'm a little confused by the tests; IndexTest::testMapping seems to be testing Type::getMapping, while TypeTest::testGetMappingAlias seems to test Index::getMapping :/

@ruflin
Copy link
Owner

ruflin commented Apr 20, 2014

Hm, good point. Seems like I mixed up some stuff :-( It would be really nice if you could directly clean that up and rename / move the functions to the right place. Sorry about that.

@ruflin
Copy link
Owner

ruflin commented Apr 21, 2014

Will close this one as the pull request is merged. Otherwise, please reopen it.

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

No branches or pull requests

2 participants