0

I'm having some problems with a query, I have a nested document

Array
(
    [took] => 2
    [timed_out] => 
    [_shards] => Array
        (
            [total] => 5
            [successful] => 5
            [failed] => 0
        )

    [hits] => Array
        (
            [total] => 1
            [max_score] => 1
            [hits] => Array
                (
                    [0] => Array
                        (
                            [_index] => holiday
                            [_type] => holiday
                            [_id] => 31245
                            [_score] => 1
                            [_source] => Array
                                (
                                    [username] => john thomas
                                    [user] => 3
                                    [info] => test
                                    [phone] => 166872
                                    [data] => Array
                                        (
                                            [foo] => 28865
                                            [bar] => new test
                                        )

                                )

                        )

                )

        )

)

When I run a standard query with the elasticsearch php library

$client = new Elasticsearch\Client();

$params['index'] = 'holiday';
$params['type']  = 'holiday';
$params['body']['query']['match']['phone'] = '166872';

$results = $client->search($params);

echo '<pre>' , print_r($results) , '</pre>';

I get a result. But when I change the query parameter to search foo

$params['body']['query']['match']['data']['foo'] = '28865';

I get an exception being thrown

{
  "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
            shardFailures {[9J2ZatYTTV2Sk8LQFKFeXg][holiday][2]:
            SearchParseException[[holiday][2]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "match": {
                      "data": {
                        "foo": "28865"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][3]:
            SearchParseException[[holiday][3]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "match": {
                      "data": {
                        "foo": "28865"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][0]:
            SearchParseException[[holiday][0]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "match": {
                      "data": {
                        "foo": "28865"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][1]:
            SearchParseException[[holiday][1]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "match": {
                      "data": {
                        "foo": "28865"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }{[9J2ZatYTTV2Sk8LQFKFeXg][holiday][4]:
            SearchParseException[[holiday][4]: from[-1],size[-1]:
              Parse Failure [Failed to parse source [
                {
                  "query": {
                    "match": {
                      "data": {
                        "foo": "28865"
                      }
                    }
                  }
                }
              ]]];
            nested: QueryParsingException[[holiday] [match] query does not support [foo]]; }]",
  "status": 400
}

Any ideas why the nested query is breaking?

1 Answer 1

3

If you use the default mapping, the data field has been dynamically mapped to type object (documentation here).

Consequently, to query on a sub-property of your object, you should use dot notation like this :

{
  "query": {
    "match": {
      "data.foo": "28865"
    }
  }  
}
Sign up to request clarification or add additional context in comments.

Comments

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.