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

Add dedicated /_search/template endpoint for query templates #5353

Closed

Conversation

spinscale
Copy link
Contributor

In order to simplify query template execution an own endpoint has been added

  • Rest tests and another unit test added
  • Changed the RestApiSpecParser to throw a more useful exception

Open question: Should the JAVA APIs change as well?

}
},
"body": {
"description": "The search definiation template"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo :)

@s1monw
Copy link
Contributor

s1monw commented Mar 13, 2014

I like it a lot! I think it looks pretty cool left some minor comments

@spinscale
Copy link
Contributor Author

updated the PR based on your comments

spinscale added a commit to spinscale/elasticsearch that referenced this pull request Mar 14, 2014
In order to simplify query template execution an own endpoint has been added

Closes elastic#5353
"size" : {{mySize}}
},
"params" : {
"myField" : "foo",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have more reasonable names / values here maybe use an example that is more realistic like filter for a username or so?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also suggest that we use my_value which is less javaish?

@s1monw
Copy link
Contributor

s1monw commented Mar 14, 2014

a small amount of comments but LGTM !!

}
}
------------------------------------------


For more information on how Mustache templating and what kind of templating you
can do with it check out the [online

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect asciidoc link syntax here. Use: http://foo.com[Name]

@clintongormley
Copy link

I'd love to see some examples of more complicated templates, including mustache sections, use of arrays etc.

Also, is the automatic html encoding of output turned off?

@spinscale
Copy link
Contributor Author

hrm...

{
    "template" : {
        "query": { "filtered" : {
            "query" : { "match_all" : {} },
            "filter" : { "owner" : "{{user}}" }
         },
        "aggs" : {
        {{#aggs}}
          "{{.}}" : { "terms" : { "field" : "{{.}}" }  }
        {{/aggs}}
        }
    },
    "params" : {
        "user" : "kimchy",
        "aggs" : [ "category_id", "sub_category_id" ]
    }
}

something like this will not produce valid JSON, as you cannot check for the last element of an array with mustache, thanks to logicless template... need to think about this in order to solve it nicely, makes mustache somewhat limited here for our needs...

@clintongormley
Copy link

i do wonder if mustache is the right answer here... You can certainly make it do the right thing, but I wonder how easy it will be for the user to write.

@s1monw
Copy link
Contributor

s1monw commented Mar 14, 2014

it's just a scripting engine so you can plug in whatever produces a string?

@clintongormley
Copy link

yeah, but i'm thinking more of the existing dsl with some added operators... not sure. need to play with it a bit

@clintongormley
Copy link

OK I've worked through various non-trivial examples of templating using mustache, and added a number of worked examples to the docs page: See spinscale#2

There are some things (conditional clauses) which can't be expressed using the JSON form of templates, but can be expressed as strings. I've included an example in the PR.

One thing that needs to be fixed is the escape method. Currently it escapes characters as expected for HTML, eg " -> ". This is clearly wrong. Instead, we should be using these escapes:

\b  Backspace (ascii code 08)
\f  Form feed (ascii code 0C)
\n  New line
\r  Carriage return
\t  Tab
\v  Vertical tab
\"  Double quote
\\  Backslash 

In order to simplify query template execution an own endpoint has been added

Closes elastic#5353
@s1monw
Copy link
Contributor

s1monw commented Mar 20, 2014

LGTM lets push this @spinscale

@clintongormley
Copy link

I've opened the escaping bug as a separate issue #5473

@spinscale spinscale closed this in 8f6e1d4 Mar 20, 2014
spinscale added a commit that referenced this pull request Mar 20, 2014
In order to simplify query template execution an own endpoint has been added

Closes #5353
@spinscale spinscale mentioned this pull request Mar 28, 2014
karmi added a commit to elastic/elasticsearch-ruby that referenced this pull request Apr 9, 2014
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed >feature labels Jun 6, 2015
@clintongormley clintongormley changed the title Query Templates: Adding dedicated /_search/template endpoint Add dedicated /_search/template endpoint for query templates Jun 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories v1.1.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants