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 predefined search templates endpoint #5637

Closed
dadoonet opened this issue Apr 1, 2014 · 3 comments
Closed

Add predefined search templates endpoint #5637

dadoonet opened this issue Apr 1, 2014 · 3 comments
Assignees

Comments

@dadoonet
Copy link
Member

dadoonet commented Apr 1, 2014

New feature #5122 allows storing query templates on local nodes.

We should add some endpoints to allow:

Put/Update a search template:

PUT _search/template/templatename
{
    "template" : {
        "content" : {
            "query": {
                "match_{{te_1}}": {}
            },
            "fac{{te_2}}": {
            "list-id": {
                "terms": {
                    "field": "list-{{te_3}}",
                    "size": 10
                }
            }
            }, 
            "fields": ["subject", "from"]
        }
    }
}

Get a search template:

GET _search/template/templatename

Remove a search template:

DELETE _search/template/templatename

Run the template:

GET /_search/template
{
    "template": "templatename" ,
    "params": {
        "te_1" : "all",
        "te_2" : "ets",
        "te_3" : "id"
    }
}

Search for all templates:

GET _search/template
GET _search/template/_all
GET _search/template/*
@s1monw
Copy link
Contributor

s1monw commented Apr 1, 2014

just an idea, can a template be index/type/id then we can just use an arbitrary index for storing the templates as a start and it's replicated, versioned and the infra is tested? The search can then just do a get call and get the template?

@dadoonet
Copy link
Member Author

dadoonet commented Apr 1, 2014

w00t! I love it @s1monw. Because I was not confortable of having this in cluster state! :)

I think we will need to cache the template if we don't want to load/compile it on each call.

@GaelTadh GaelTadh self-assigned this Apr 15, 2014
GaelTadh added a commit to GaelTadh/elasticsearch that referenced this issue Jul 1, 2014
… search time

This change allows search templates stored in an index to be used at search time.
You can run an indexed template by
GET /_search/template
{
    'templatename' : '/index/language/id',
    'params' : {
        'param1' : 'foo'
    }
}
Running the template will fail if the template cannot be found, if the templatename
starts with a '/' but does not conform to the /index/type/id triple
If the named template cannot be found an error will be raised. Currently the
templates are NOT cached. We also use TransportGetAction directly instead of using
Client to avoid a circular dependency between Client and ScriptService

See elastic#5637
GaelTadh added a commit to GaelTadh/elasticsearch that referenced this issue Jul 1, 2014
This change allows the creation,update and deletion of indexed templates via the _search/template/{id} endpoint.
Storing a template :
curl -XPUT 'http://localhost:9200/_search/template/1a' -d '
{
  "template": {
    "query": { "match_all": {}},
    "size": "{{my_size}}"
  }
}'
Deleting a template:
curl -XDELETE 'http://localhost:9200/_search/template/1a'
Getting a template:
curl -XGET 'http://localhost:9200/_search/template/1a'
Using an indexed template:
curl -XGET 'http://localhost:9200/_search/template' -d '
{
  "template":
  {
    "id" : "1a"
  },
  "params": {
    "my_size": 100
  }
}'
Or more simply:
curl -XGET 'http://localhost:9200/_search/template' -d '
{
  "id" : "1a",
  "params": {
    "my_size": 100
  }
}'
To access on disk templates in template queries the file parameter must now be used. This does break backwards compatiblity with previous versions
since the template "query" was previously aliased to dynamic inline templates or on disk templates.

See elastic#5637
GaelTadh added a commit to GaelTadh/elasticsearch that referenced this issue Jul 1, 2014
This rest test indexes a template then uses it in search.

See elastic#5637
GaelTadh added a commit to GaelTadh/elasticsearch that referenced this issue Jul 14, 2014
… search time

This change allows search templates stored in an index to be used at search time.
You can run an indexed template by
GET /_search/template
{
    'templatename' : '/index/language/id',
    'params' : {
        'param1' : 'foo'
    }
}
Running the template will fail if the template cannot be found, if the templatename
starts with a '/' but does not conform to the /index/type/id triple
If the named template cannot be found an error will be raised. Currently the
templates are NOT cached. We also use TransportGetAction directly instead of using
Client to avoid a circular dependency between Client and ScriptService

See elastic#5637
GaelTadh added a commit to GaelTadh/elasticsearch that referenced this issue Jul 14, 2014
This change allows the creation,update and deletion of indexed templates via the _search/template/{id} endpoint.
Storing a template :
curl -XPUT 'http://localhost:9200/_search/template/1a' -d '
{
  "template": {
    "query": { "match_all": {}},
    "size": "{{my_size}}"
  }
}'
Deleting a template:
curl -XDELETE 'http://localhost:9200/_search/template/1a'
Getting a template:
curl -XGET 'http://localhost:9200/_search/template/1a'
Using an indexed template:
curl -XGET 'http://localhost:9200/_search/template' -d '
{
  "template":
  {
    "id" : "1a"
  },
  "params": {
    "my_size": 100
  }
}'
Or more simply:
curl -XGET 'http://localhost:9200/_search/template' -d '
{
  "id" : "1a",
  "params": {
    "my_size": 100
  }
}'
To access on disk templates in template queries the file parameter must now be used. This does break backwards compatiblity with previous versions
since the template "query" was previously aliased to dynamic inline templates or on disk templates.

See elastic#5637
GaelTadh added a commit to GaelTadh/elasticsearch that referenced this issue Jul 14, 2014
This rest test indexes a template then uses it in search.

See elastic#5637
GaelTadh added a commit that referenced this issue Jul 14, 2014
…cripts/template from an index.

This change allow elasticsearch users to store scripts and templates in an index for use at search time.
Scripts/Templates are stored in the .scripts index. The type of the events is set to the script language.
Templates use the mustache language so their type is be "mustache".
Adds the concept of a script type to calls to the ScriptService types are INDEXED,INLINE,FILE.
If a script type of INDEXED is supplied the script will be attempted to be loaded from the indexed, FILE will
look in the file cache and INLINE will treat the supplied script argument as the literal script.
REST endpoints are provided to do CRUD operations as is a java client library.
All query dsl points have been upgraded to allow passing in of explicit script ids and script file names.
Backwards compatible behavior has been preserved so this shouldn't break any existing querys that expect to
pass in a filename as the script/template name. The ScriptService will check the disk cache before parsing the
script.

Closes #5921 #5637 #5484
GaelTadh added a commit that referenced this issue Jul 14, 2014
…cripts/template from an index.

This change allow elasticsearch users to store scripts and templates in an index for use at search time.
Scripts/Templates are stored in the .scripts index. The type of the events is set to the script language.
Templates use the mustache language so their type is be "mustache".
Adds the concept of a script type to calls to the ScriptService types are INDEXED,INLINE,FILE.
If a script type of INDEXED is supplied the script will be attempted to be loaded from the indexed, FILE will
look in the file cache and INLINE will treat the supplied script argument as the literal script.
REST endpoints are provided to do CRUD operations as is a java client library.
All query dsl points have been upgraded to allow passing in of explicit script ids and script file names.
Backwards compatible behavior has been preserved so this shouldn't break any existing querys that expect to
pass in a filename as the script/template name. The ScriptService will check the disk cache before parsing the
script.

Closes #5921 #5637 #5484
@GaelTadh GaelTadh added v1.3.0 and removed v1.3.0 labels Jul 14, 2014
@GaelTadh
Copy link
Contributor

Closed by e79b708

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

4 participants