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

Failed to derive xcontent on template queries #9458

Closed
micpalmia opened this issue Jan 28, 2015 · 3 comments
Closed

Failed to derive xcontent on template queries #9458

micpalmia opened this issue Jan 28, 2015 · 3 comments

Comments

@micpalmia
Copy link
Contributor

With ES 1.4 on my local (iOS) machine with all the default settings, I get a SearchPhaseExecutionException when trying to execute a template query.

Please find the described steps below.

# store the search template
curl -XPUT "http://localhost:9200/_search/template/testSearch" -d'
{
    "template": {"query": {"match_all": {}}}
}'

# it seems to be correctly stored
curl -XGET "http://localhost:9200/_search/template/testSearch"

# using the template endpoint works fine
curl -XGET "http://localhost:9200/.scripts/_search/template" -d'
{
    "template": {
        "id": "testSearch" 
    }
}'

# but using a completely equivalent template query doesn't
curl -XGET "http://localhost:9200/.scripts/_search" -d'
{
    "query": {
        "template": {
            "query": "testSearch", 
            "params" : {}
        }
    }
}'

Please find the complete stack trace below

[2015-01-28 12:35:20,513][DEBUG][action.search.type       ] [Yukon Jack] [.scripts][0], node[Yax3V7rFQt2UQcQoYfDy-Q], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@2c968bee]
org.elasticsearch.search.SearchParseException: [.scripts][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{
    "query": {
        "template": {
            "query": "testSearch",
            "params" : {}
        }
    }
}
]]
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:681)
    at org.elasticsearch.search.SearchService.createContext(SearchService.java:537)
    at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:509)
    at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:350)
    at org.elasticsearch.search.action.SearchServiceTransportAction$11.call(SearchServiceTransportAction.java:333)
    at org.elasticsearch.search.action.SearchServiceTransportAction$11.call(SearchServiceTransportAction.java:330)
    at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.ElasticsearchParseException: Failed to derive xcontent from org.elasticsearch.common.bytes.PagedBytesReference@fb05139b
    at org.elasticsearch.common.xcontent.XContentFactory.xContent(XContentFactory.java:259)
    at org.elasticsearch.index.query.TemplateQueryParser.parse(TemplateQueryParser.java:85)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:277)
    at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:382)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:281)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:276)
    at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:665)
    ... 9 more
[2015-01-28 12:35:20,515][DEBUG][action.search.type       ] [Yukon Jack] All shards failed for phase: [query_fetch]
@dadoonet
Copy link
Member

I think you should do something like:

PUT test

DELETE _search/template/testSearch

POST _search/template/testSearch
{
    "template": {"query": {"match_all": {}}}
}

GET _search/template/testSearch

GET test/_search/template
{
    "template": {
        "id": "testSearch" 
    }
}

See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html

@micpalmia
Copy link
Contributor Author

I appreciate the fact that the template endpoint (referenced in the page you linked) works, but the template query (link attached to my first message) doesn't, even with your set up.

After the set up in your message, you can try the following to check that it's not working.

curl -XGET "http://localhost:9200/test/_search" -d'
{
    "query": {
        "template": {
            "query": "testSearch", 
            "params" : {}
        }
    }
}'

clintongormley added a commit that referenced this issue Jan 28, 2015
Added the `file` and `id` parameters.

Closes #9458
clintongormley added a commit that referenced this issue Jan 28, 2015
Added the `file` and `id` parameters.

Closes #9458
@clintongormley
Copy link

@micpalmia use id instead of query - I've just pushed a fix to the docs

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
Added the `file` and `id` parameters.

Closes elastic#9458
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

3 participants