Nested Query


(kikster) #1

I created a tweet mapping with a nested field calls "comments" (localhost:9200/twitter/tweet/_mapping)

{"tweet":{"properties":{"message":{"type":"string"},"user":{"type":"string"},"comments":{"properties":{"text":{"type":"string"},"name":{"type":"string"}},"type":"nested"}}}}

I added a few entries to it and tried to issue a nested query as follows.

curl -XGET 'http://localhost.com:9200/twitter/tweet/_search' -d
'{"nested" :
{ "path": "comments",
"query" :
{"query_string" :
{"query" : "Johnny"}}}}'

However I get the following error:

{"error":"SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[pVbYE8kxSnKqAI1Fn9FMWA][twitter][0]: SearchParseException[[twitter][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"nested" : {"path" : "tweet.comments", "query" : "hello"}}]]]; nested: SearchParseException[[twitter][0]: from[-1],size[-1]: Parse Failure [No parser for element [nested]]]; }{[pVbYE8kxSnKqAI1Fn9FMWA][twitter][1]: SearchParseException[[twitter][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"nested" : {"path" : "tweet.comments", "query" : "hello"}}]]]; nested: SearchParseException[[twitter][1]: from[-1],size[-1]: Parse Failure [No parser for element [nested]]]; }{[pVbYE8kxSnKqAI1Fn9FMWA][twitter][2]: SearchParseException[[twitter][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"nested" : {"path" : "tweet.comments", "query" : "hello"}}]]]; nested: SearchParseException[[twitter][2]: from[-1],size[-1]: Parse Failure [No parser for element [nested]]]; }{[pVbYE8kxSnKqAI1Fn9FMWA][twitter][3]: SearchParseException[[twitter][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"nested" : {"path" : "tweet.comments", "query" : "hello"}}]]]; nested: SearchParseException[[twitter][3]: from[-1],size[-1]: Parse Failure [No parser for element [nested]]]; }{[pVbYE8kxSnKqAI1Fn9FMWA][twitter][4]: SearchParseException[[twitter][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"nested" : {"path" : "tweet.comments", "query" : "hello"}}]]]; nested: SearchParseException[[twitter][4]: from[-1],size[-1]: Parse Failure [No parser for element [nested]]]; }]","status":500}

I've read the documentation a million times and am pretty sure I've done everything required. Any idea as to why the query is failing to parse?


(ofavre) #2

The documentation is not clear enough for beginners. It needs some practice
to better understand it.

You missed (at least) one thing:
The excerpts given (like in
http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)
are only a part of the whole query.
May be this page will help you too:
http://www.elasticsearch.org/guide/reference/api/search/request-body.html
As queries can be nested, the documentation skips the... wrapping (I can't
find a better term...)
A minimum wrapping in order to create a "request body" from a simple query
is:
{
"query":
{ ...put your query here... }
}

Here is what your call should look like:
curl -XGET 'http://www.tutorcrew.com:9200/twitter/tweet/_search' -d
'{

  • "query" : *{
    "nested" : {
    "path" : "comments",
    "query" : {
    "query_string" : {
    "query" : "Johnny"
    }
    }
    }
    }
    }'

Also, make sure your mapping is correct:
http://www.elasticsearch.org/guide/reference/mapping/nested-type.html
It should be just like the "object" mapping (
http://www.elasticsearch.org/guide/reference/mapping/object-type.html), but
with "type":"nested" instead of "type":"object".
And like for the query, there is a minimum wrapping for integrating the
documentation excerpts.
The following command should help you see what the current mapping is (not
sure how it works for dynamic mappings):
curl -XGET 'http://www.tutorcrew.com:9200/twitter/tweet/_mapping?pretty=1'

Happy experiencing with ElasticSearch!

Olivier Favre

2011/7/25 cdolive [via ElasticSearch Users] <
ml-node+3196303-72493033-393975@n3.nabble.com>

I created a tweet mapping with a nested field calls "comments"
(localhost:9200/twitter/tweet/_mapping)

{"tweet":{"properties":{"message":{"type":"string"},"user":{"type":"string"},"comments":{"properties":{"text":{"type":"string"},"name":{"type":"string"}},"type":"nested"}}}}

I added a few entries to it and tried to issue a nested query as follows.

curl -XGET 'http://www.tutorcrew.com:9200/twitter/tweet/_search' -d
'{"nested" :
{ "path": "comments",
"query" :
{"query_string" :
{"query" : "Johnny"}}}}'

However I get the following error:

{"error":"SearchPhaseExecutionException[Failed to execute phase [query],
total failure; shardFailures {[pVbYE8kxSnKqAI1Fn9FMWA][twitter][0]:
SearchParseException[[twitter][0]: from[-1],size[-1]: Parse Failure [Failed
to parse source [{"nested" : {"path" : "tweet.comments", "query" :
"hello"}}]]]; nested: SearchParseException[[twitter][0]:
from[-1],size[-1]: Parse Failure [No parser for element [nested]]];
}{[pVbYE8kxSnKqAI1Fn9FMWA][twitter][1]: SearchParseException[[twitter][1]:
from[-1],size[-1]: Parse Failure [Failed to parse source [{"nested" :
{"path" : "tweet.comments", "query" : "hello"}}]]]; nested:
SearchParseException[[twitter][1]: from[-1],size[-1]: Parse Failure [No
parser for element [nested]]]; }{[pVbYE8kxSnKqAI1Fn9FMWA][twitter][2]:
SearchParseException[[twitter][2]: from[-1],size[-1]: Parse Failure [Failed
to parse source [{"nested" : {"path" : "tweet.comments", "query" :
"hello"}}]]]; nested: SearchParseException[[twitter][2]:
from[-1],size[-1]: Parse Failure [No parser for element [nested]]];
}{[pVbYE8kxSnKqAI1Fn9FMWA][twitter][3]: SearchParseException[[twitter][3]:
from[-1],size[-1]: Parse Failure [Failed to parse source [{"nested" :
{"path" : "tweet.comments", "query" : "hello"}}]]]; nested:
SearchParseException[[twitter][3]: from[-1],size[-1]: Parse Failure [No
parser for element [nested]]]; }{[pVbYE8kxSnKqAI1Fn9FMWA][twitter][4]:
SearchParseException[[twitter][4]: from[-1],size[-1]: Parse Failure [Failed
to parse source [{"nested" : {"path" : "tweet.comments", "query" :
"hello"}}]]]; nested: SearchParseException[[twitter][4]:
from[-1],size[-1]: Parse Failure [No parser for element [nested]]];
}]","status":500}

I've read the documentation a million times and am pretty sure I've done
everything required. Any idea as to why the query is failing to parse?


If you reply to this email, your message will be added to the discussion
below:

http://elasticsearch-users.115913.n3.nabble.com/Nested-Query-tp3196303p3196303.html
To start a new topic under ElasticSearch Users, email
ml-node+115913-1699315842-393975@n3.nabble.com
To unsubscribe from ElasticSearch Users, click herehttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=115913&code=b2xpdmllckB5YWthei5jb218MTE1OTEzfDIxMjI2MTYwOTc=.


(system) #3