"Fossies" - the Fresh Open Source Software Archive

Member "elasticsearch-6.8.23/docs/build.gradle" (29 Dec 2021, 41764 Bytes) of package /linux/www/elasticsearch-6.8.23-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Java source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 /*
    2  * Licensed to Elasticsearch under one or more contributor
    3  * license agreements. See the NOTICE file distributed with
    4  * this work for additional information regarding copyright
    5  * ownership. Elasticsearch licenses this file to you under
    6  * the Apache License, Version 2.0 (the "License"); you may
    7  * not use this file except in compliance with the License.
    8  * You may obtain a copy of the License at
    9  *
   10  *    http://www.apache.org/licenses/LICENSE-2.0
   11  *
   12  * Unless required by applicable law or agreed to in writing,
   13  * software distributed under the License is distributed on an
   14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15  * KIND, either express or implied.  See the License for the
   16  * specific language governing permissions and limitations
   17  * under the License.
   18  */
   19 
   20 apply plugin: 'elasticsearch.docs-test'
   21 
   22 /* List of files that have snippets that will not work until platinum tests can occur ... */
   23 buildRestTests.expectedUnconvertedCandidates = [
   24         'reference/ml/transforms.asciidoc',
   25         'reference/ml/apis/delete-calendar-event.asciidoc',
   26         'reference/ml/apis/get-bucket.asciidoc',
   27         'reference/ml/apis/get-category.asciidoc',
   28         'reference/ml/apis/get-influencer.asciidoc',
   29         'reference/ml/apis/get-job-stats.asciidoc',
   30         'reference/ml/apis/get-overall-buckets.asciidoc',
   31         'reference/ml/apis/get-record.asciidoc',
   32         'reference/ml/apis/get-snapshot.asciidoc',
   33         'reference/ml/apis/post-data.asciidoc',
   34         'reference/ml/apis/revert-snapshot.asciidoc',
   35         'reference/ml/apis/update-snapshot.asciidoc',
   36 ]
   37 
   38 integTestCluster {
   39   if ("zip".equals(integTestCluster.distribution)) {
   40     setting 'xpack.license.self_generated.type', 'trial'
   41   }
   42 
   43   // enable regexes in painless so our tests don't complain about example snippets that use them
   44   setting 'script.painless.regex.enabled', 'true'
   45   Closure configFile = {
   46     extraConfigFile it, "src/test/cluster/config/$it"
   47   }
   48   configFile 'analysis/example_word_list.txt'
   49   configFile 'analysis/hyphenation_patterns.xml'
   50   configFile 'analysis/synonym.txt'
   51   configFile 'analysis/stemmer_override.txt'
   52   configFile 'userdict_ja.txt'
   53   configFile 'userdict_ko.txt'
   54   configFile 'KeywordTokenizer.rbbi'
   55   extraConfigFile 'hunspell/en_US/en_US.aff', '../server/src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.aff'
   56   extraConfigFile 'hunspell/en_US/en_US.dic', '../server/src/test/resources/indices/analyze/conf_dir/hunspell/en_US/en_US.dic'
   57   // Whitelist reindexing from the local node so we can test it.
   58   setting 'reindex.remote.whitelist', '127.0.0.1:*'
   59 
   60   // TODO: remove this for 7.0, this exists to allow the doc examples in 6.x to continue using the defaults
   61   systemProperty 'es.scripting.update.ctx_in_params', 'false'
   62 
   63   //TODO: remove this once the cname is prepended to the address by default in 7.0
   64   systemProperty 'es.http.cname_in_publish_address', 'true'
   65 
   66   // TODO: remove this deprecation compatibility setting for 7.0
   67   systemProperty 'es.aggregations.enable_scripted_metric_agg_param', 'false'
   68 }
   69 
   70 // build the cluster with all plugins
   71 project.rootProject.subprojects.findAll { it.parent.path == ':plugins' }.each { subproj ->
   72   /* Skip repositories. We just aren't going to be able to test them so it
   73    * doesn't make sense to waste time installing them.
   74    */
   75   if (subproj.path.startsWith(':plugins:repository-')) {
   76     return
   77   }
   78   subproj.afterEvaluate { // need to wait until the project has been configured
   79     integTestCluster {
   80       plugin subproj.path
   81     }
   82   }
   83 }
   84 
   85 buildRestTests.docs = fileTree(projectDir) {
   86   // No snippets in here!
   87   exclude 'build.gradle'
   88   // That is where the snippets go, not where they come from!
   89   exclude 'build'
   90   // Just syntax examples
   91   exclude 'README.asciidoc'
   92   // Broken code snippet tests
   93   exclude 'reference/graph/explore.asciidoc'
   94 }
   95 
   96 listSnippets.docs = buildRestTests.docs
   97 
   98 Closure setupTwitter = { String name, int count ->
   99   buildRestTests.setups[name] = '''
  100   - do:
  101         indices.create:
  102           index: twitter
  103           body:
  104             settings:
  105               number_of_shards: 1
  106               number_of_replicas: 1
  107             mappings:
  108               _doc:
  109                 properties:
  110                   user:
  111                     type: keyword
  112                     doc_values: true
  113                   date:
  114                     type: date
  115                   likes:
  116                     type: long
  117   - do:
  118         bulk:
  119           index: twitter
  120           type: _doc
  121           refresh: true
  122           body: |'''
  123     for (int i = 0; i < count; i++) {
  124       String user, text
  125       if (i == 0) {
  126         user = 'kimchy'
  127         text = 'trying out Elasticsearch'
  128       } else {
  129         user = 'test'
  130         text = "some message with the number $i"
  131       }
  132       buildRestTests.setups[name] += """
  133             {"index":{"_id": "$i"}}
  134             {"user": "$user", "message": "$text", "date": "2009-11-15T14:12:12", "likes": $i}"""
  135     }
  136   }
  137 setupTwitter('twitter', 5)
  138 setupTwitter('big_twitter', 120)
  139 setupTwitter('huge_twitter', 1200)
  140 
  141 buildRestTests.setups['host'] = '''
  142   # Fetch the http host. We use the host of the master because we know there will always be a master.
  143   - do:
  144       cluster.state: {}
  145   - set: { master_node: master }
  146   - do:
  147       nodes.info:
  148         metric: [ http, transport ]
  149   - set: {nodes.$master.http.publish_address: host}
  150   - set: {nodes.$master.transport.publish_address: transport_host}
  151 '''
  152 
  153 buildRestTests.setups['node'] = '''
  154   # Fetch the node name. We use the host of the master because we know there will always be a master.
  155   - do:
  156       cluster.state: {}
  157   - is_true: master_node
  158   - set: { master_node: node_name }
  159 '''
  160 
  161 // Used by scripted metric docs
  162 buildRestTests.setups['ledger'] = '''
  163   - do:
  164         indices.create:
  165           index: ledger
  166           body:
  167             settings:
  168               number_of_shards: 2
  169               number_of_replicas: 1
  170             mappings:
  171               _doc:
  172                 properties:
  173                   type:
  174                     type: keyword
  175                   amount:
  176                     type: double
  177   - do:
  178         bulk:
  179           index: ledger
  180           type: _doc
  181           refresh: true
  182           body: |
  183             {"index":{}}
  184             {"date": "2015/01/01 00:00:00", "amount": 200, "type": "sale", "description": "something"}
  185             {"index":{}}
  186             {"date": "2015/01/01 00:00:00", "amount": 10, "type": "expense", "decription": "another thing"}
  187             {"index":{}}
  188             {"date": "2015/01/01 00:00:00", "amount": 150, "type": "sale", "description": "blah"}
  189             {"index":{}}
  190             {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "cost of blah"}
  191             {"index":{}}
  192             {"date": "2015/01/01 00:00:00", "amount": 50, "type": "expense", "description": "advertisement"}'''
  193 
  194 // Used by aggregation docs
  195 buildRestTests.setups['sales'] = '''
  196   - do:
  197         indices.create:
  198           index: sales
  199           body:
  200             settings:
  201               number_of_shards: 2
  202               number_of_replicas: 1
  203             mappings:
  204               _doc:
  205                 properties:
  206                   type:
  207                     type: keyword
  208   - do:
  209         bulk:
  210           index: sales
  211           type: _doc
  212           refresh: true
  213           body: |
  214             {"index":{}}
  215             {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  216             {"index":{}}
  217             {"date": "2015/01/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "t-shirt"}
  218             {"index":{}}
  219             {"date": "2015/01/01 00:00:00", "price": 150, "promoted": true, "rating": 5, "type": "bag"}
  220             {"index":{}}
  221             {"date": "2015/02/01 00:00:00", "price": 50, "promoted": false, "rating": 1, "type": "hat"}
  222             {"index":{}}
  223             {"date": "2015/02/01 00:00:00", "price": 10, "promoted": true, "rating": 4, "type": "t-shirt"}
  224             {"index":{}}
  225             {"date": "2015/03/01 00:00:00", "price": 200, "promoted": true, "rating": 1, "type": "hat"}
  226             {"index":{}}
  227             {"date": "2015/03/01 00:00:00", "price": 175, "promoted": false, "rating": 2, "type": "t-shirt"}'''
  228 
  229 // Dummy bank account data used by getting-started.asciidoc
  230 buildRestTests.setups['bank'] = '''
  231   - do:
  232         bulk:
  233           index: bank
  234           type: _doc
  235           refresh: true
  236           body: |
  237 #bank_data#
  238 '''
  239 /* Load the actual accounts only if we're going to use them. This complicates
  240  * dependency checking but that is a small price to pay for not building a
  241  * 400kb string every time we start the build. */
  242 File accountsFile = new File("$projectDir/src/test/resources/accounts.json")
  243 buildRestTests.inputs.file(accountsFile)
  244 buildRestTests.doFirst {
  245   String accounts = accountsFile.getText('UTF-8')
  246   // Indent like a yaml test needs
  247   accounts = accounts.replaceAll('(?m)^', '            ')
  248   buildRestTests.setups['bank'] =
  249     buildRestTests.setups['bank'].replace('#bank_data#', accounts)
  250 }
  251 
  252 // Used by index boost doc
  253 buildRestTests.setups['index_boost'] = '''
  254   - do:
  255       indices.create:
  256           index:  index1
  257   - do:
  258       indices.create:
  259           index:  index2
  260 
  261   - do:
  262       indices.put_alias:
  263         index: index1
  264         name: alias1
  265 '''
  266 // Used by sampler and diversified-sampler aggregation docs
  267 buildRestTests.setups['stackoverflow'] = '''
  268   - do:
  269         indices.create:
  270           index: stackoverflow
  271           body:
  272             settings:
  273               number_of_shards: 1
  274               number_of_replicas: 1
  275             mappings:
  276               _doc:
  277                 properties:
  278                   author:
  279                     type: keyword
  280                   tags:
  281                     type: keyword
  282   - do:
  283         bulk:
  284           index: stackoverflow
  285           type: _doc
  286           refresh: true
  287           body: |'''
  288 
  289 // Make Kibana strongly connected to elasticsearch and logstash
  290 // Make Kibana rarer (and therefore higher-ranking) than JavaScript
  291 // Make JavaScript strongly connected to jquery and angular
  292 // Make Cabana strongly connected to elasticsearch but only as a result of a single author
  293 
  294 for (int i = 0; i < 150; i++) {
  295   buildRestTests.setups['stackoverflow'] += """
  296             {"index":{}}
  297             {"author": "very_relevant_$i", "tags": ["elasticsearch", "kibana"]}"""
  298 }
  299 for (int i = 0; i < 50; i++) {
  300   buildRestTests.setups['stackoverflow'] += """
  301             {"index":{}}
  302             {"author": "very_relevant_$i", "tags": ["logstash", "kibana"]}"""
  303 }
  304 for (int i = 0; i < 200; i++) {
  305   buildRestTests.setups['stackoverflow'] += """
  306             {"index":{}}
  307             {"author": "partially_relevant_$i", "tags": ["javascript", "jquery"]}"""
  308 }
  309 for (int i = 0; i < 200; i++) {
  310   buildRestTests.setups['stackoverflow'] += """
  311             {"index":{}}
  312             {"author": "partially_relevant_$i", "tags": ["javascript", "angular"]}"""
  313 }
  314 for (int i = 0; i < 50; i++) {
  315   buildRestTests.setups['stackoverflow'] += """
  316             {"index":{}}
  317             {"author": "noisy author", "tags": ["elasticsearch", "cabana"]}"""
  318 }
  319 buildRestTests.setups['stackoverflow'] += """
  320 """
  321 // Used by significant_text aggregation docs
  322 buildRestTests.setups['news'] = '''
  323   - do:
  324         indices.create:
  325           index: news
  326           body:
  327             settings:
  328               number_of_shards: 1
  329               number_of_replicas: 1
  330             mappings:
  331               _doc:
  332                 properties:
  333                   source:
  334                     type: keyword
  335                   content:
  336                     type: text
  337   - do:
  338         bulk:
  339           index: news
  340           type: _doc
  341           refresh: true
  342           body: |'''
  343 
  344 // Make h5n1 strongly connected to bird flu
  345 
  346 for (int i = 0; i < 100; i++) {
  347   buildRestTests.setups['news'] += """
  348             {"index":{}}
  349             {"source": "very_relevant_$i", "content": "bird flu h5n1"}"""
  350 }
  351 for (int i = 0; i < 100; i++) {
  352   buildRestTests.setups['news'] += """
  353             {"index":{}}
  354             {"source": "filler_$i", "content": "bird dupFiller "}"""
  355 }
  356 for (int i = 0; i < 100; i++) {
  357   buildRestTests.setups['news'] += """
  358             {"index":{}}
  359             {"source": "filler_$i", "content": "flu dupFiller "}"""
  360 }
  361 for (int i = 0; i < 20; i++) {
  362   buildRestTests.setups['news'] += """
  363             {"index":{}}
  364             {"source": "partially_relevant_$i", "content": "elasticsearch dupFiller dupFiller dupFiller dupFiller pozmantier"}"""
  365 }
  366 for (int i = 0; i < 10; i++) {
  367   buildRestTests.setups['news'] += """
  368             {"index":{}}
  369             {"source": "partially_relevant_$i", "content": "elasticsearch logstash kibana"}"""
  370 }
  371 buildRestTests.setups['news'] += """
  372 """
  373 
  374 // Used by some aggregations
  375 buildRestTests.setups['exams'] = '''
  376   - do:
  377         indices.create:
  378           index: exams
  379           body:
  380             settings:
  381               number_of_shards: 1
  382               number_of_replicas: 1
  383             mappings:
  384               _doc:
  385                 properties:
  386                   grade:
  387                     type: byte
  388   - do:
  389         bulk:
  390           index: exams
  391           type: _doc
  392           refresh: true
  393           body: |
  394             {"index":{}}
  395             {"grade": 100, "weight": 2}
  396             {"index":{}}
  397             {"grade": 50, "weight": 3}'''
  398 
  399 buildRestTests.setups['stored_example_script'] = '''
  400   # Simple script to load a field. Not really a good example, but a simple one.
  401   - do:
  402       put_script:
  403         id: "my_script"
  404         body: { "script": { "lang": "painless", "source": "doc[params.field].value" } }
  405   - match: { acknowledged: true }
  406 '''
  407 
  408 buildRestTests.setups['stored_scripted_metric_script'] = '''
  409   - do:
  410       put_script:
  411         id: "my_init_script"
  412         body: { "script": { "lang": "painless", "source": "state.transactions = []" } }
  413   - match: { acknowledged: true }
  414 
  415   - do:
  416       put_script:
  417         id: "my_map_script"
  418         body: { "script": { "lang": "painless", "source": "state.transactions.add(doc.type.value == 'sale' ? doc.amount.value : -1 * doc.amount.value)" } }
  419   - match: { acknowledged: true }
  420 
  421   - do:
  422       put_script:
  423         id: "my_combine_script"
  424         body: { "script": { "lang": "painless", "source": "double profit = 0;for (t in state.transactions) { profit += t; } return profit" } }
  425   - match: { acknowledged: true }
  426 
  427   - do:
  428       put_script:
  429         id: "my_reduce_script"
  430         body: { "script": { "lang": "painless", "source": "double profit = 0;for (a in states) { profit += a; } return profit" } }
  431   - match: { acknowledged: true }
  432 '''
  433 
  434 // Used by analyze api
  435 buildRestTests.setups['analyze_sample'] = '''
  436   - do:
  437         indices.create:
  438           index: analyze_sample
  439           body:
  440             settings:
  441               number_of_shards: 1
  442               number_of_replicas: 0
  443               analysis:
  444                 normalizer:
  445                   my_normalizer:
  446                     type: custom
  447                     filter: [lowercase]
  448             mappings:
  449               _doc:
  450                 properties:
  451                   obj1.field1:
  452                     type: text'''
  453 
  454 // Used by percentile/percentile-rank aggregations
  455 buildRestTests.setups['latency'] = '''
  456   - do:
  457         indices.create:
  458           index: latency
  459           body:
  460             settings:
  461               number_of_shards: 1
  462               number_of_replicas: 1
  463             mappings:
  464               _doc:
  465                 properties:
  466                   load_time:
  467                     type: long
  468   - do:
  469         bulk:
  470           index: latency
  471           type: _doc
  472           refresh: true
  473           body: |'''
  474 
  475 
  476 for (int i = 0; i < 100; i++) {
  477   def value = i
  478   if (i % 10) {
  479     value = i*10
  480   }
  481   buildRestTests.setups['latency'] += """
  482             {"index":{}}
  483             {"load_time": "$value"}"""
  484 }
  485 
  486 // Used by iprange agg
  487 buildRestTests.setups['iprange'] = '''
  488   - do:
  489         indices.create:
  490           index: ip_addresses
  491           body:
  492             settings:
  493               number_of_shards: 1
  494               number_of_replicas: 1
  495             mappings:
  496               _doc:
  497                 properties:
  498                   ip:
  499                     type: ip
  500   - do:
  501         bulk:
  502           index: ip_addresses
  503           type: _doc
  504           refresh: true
  505           body: |'''
  506 
  507 
  508 for (int i = 0; i < 255; i++) {
  509   buildRestTests.setups['iprange'] += """
  510             {"index":{}}
  511             {"ip": "10.0.0.$i"}"""
  512 }
  513 for (int i = 0; i < 5; i++) {
  514   buildRestTests.setups['iprange'] += """
  515             {"index":{}}
  516             {"ip": "9.0.0.$i"}"""
  517   buildRestTests.setups['iprange'] += """
  518             {"index":{}}
  519             {"ip": "11.0.0.$i"}"""
  520   buildRestTests.setups['iprange'] += """
  521             {"index":{}}
  522             {"ip": "12.0.0.$i"}"""
  523 }
  524 
  525 // Used by SQL because it looks SQL-ish
  526 buildRestTests.setups['library'] = '''
  527   - do:
  528         indices.create:
  529           index: library
  530           body:
  531             settings:
  532               number_of_shards: 1
  533               number_of_replicas: 1
  534             mappings:
  535               book:
  536                 properties:
  537                   name:
  538                     type: text
  539                     fields:
  540                       keyword:
  541                         type: keyword
  542                   author:
  543                     type: text
  544                     fields:
  545                       keyword:
  546                         type: keyword
  547                   release_date:
  548                     type: date
  549                   page_count:
  550                     type: short
  551   - do:
  552         bulk:
  553           index: library
  554           type: book
  555           refresh: true
  556           body: |
  557             {"index":{"_id": "Leviathan Wakes"}}
  558             {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  559             {"index":{"_id": "Hyperion"}}
  560             {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  561             {"index":{"_id": "Dune"}}
  562             {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  563             {"index":{"_id": "Dune Messiah"}}
  564             {"name": "Dune Messiah", "author": "Frank Herbert", "release_date": "1969-10-15", "page_count": 331}
  565             {"index":{"_id": "Children of Dune"}}
  566             {"name": "Children of Dune", "author": "Frank Herbert", "release_date": "1976-04-21", "page_count": 408}
  567             {"index":{"_id": "God Emperor of Dune"}}
  568             {"name": "God Emperor of Dune", "author": "Frank Herbert", "release_date": "1981-05-28", "page_count": 454}
  569             {"index":{"_id": "Consider Phlebas"}}
  570             {"name": "Consider Phlebas", "author": "Iain M. Banks", "release_date": "1987-04-23", "page_count": 471}
  571             {"index":{"_id": "Pandora's Star"}}
  572             {"name": "Pandora's Star", "author": "Peter F. Hamilton", "release_date": "2004-03-02", "page_count": 768}
  573             {"index":{"_id": "Revelation Space"}}
  574             {"name": "Revelation Space", "author": "Alastair Reynolds", "release_date": "2000-03-15", "page_count": 585}
  575             {"index":{"_id": "A Fire Upon the Deep"}}
  576             {"name": "A Fire Upon the Deep", "author": "Vernor Vinge", "release_date": "1992-06-01", "page_count": 613}
  577             {"index":{"_id": "Ender's Game"}}
  578             {"name": "Ender's Game", "author": "Orson Scott Card", "release_date": "1985-06-01", "page_count": 324}
  579             {"index":{"_id": "1984"}}
  580             {"name": "1984", "author": "George Orwell", "release_date": "1985-06-01", "page_count": 328}
  581             {"index":{"_id": "Fahrenheit 451"}}
  582             {"name": "Fahrenheit 451", "author": "Ray Bradbury", "release_date": "1953-10-15", "page_count": 227}
  583             {"index":{"_id": "Brave New World"}}
  584             {"name": "Brave New World", "author": "Aldous Huxley", "release_date": "1932-06-01", "page_count": 268}
  585             {"index":{"_id": "Foundation"}}
  586             {"name": "Foundation", "author": "Isaac Asimov", "release_date": "1951-06-01", "page_count": 224}
  587             {"index":{"_id": "The Giver"}}
  588             {"name": "The Giver", "author": "Lois Lowry", "release_date": "1993-04-26", "page_count": 208}
  589             {"index":{"_id": "Slaughterhouse-Five"}}
  590             {"name": "Slaughterhouse-Five", "author": "Kurt Vonnegut", "release_date": "1969-06-01", "page_count": 275}
  591             {"index":{"_id": "The Hitchhiker's Guide to the Galaxy"}}
  592             {"name": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams", "release_date": "1979-10-12", "page_count": 180}
  593             {"index":{"_id": "Snow Crash"}}
  594             {"name": "Snow Crash", "author": "Neal Stephenson", "release_date": "1992-06-01", "page_count": 470}
  595             {"index":{"_id": "Neuromancer"}}
  596             {"name": "Neuromancer", "author": "William Gibson", "release_date": "1984-07-01", "page_count": 271}
  597             {"index":{"_id": "The Handmaid's Tale"}}
  598             {"name": "The Handmaid's Tale", "author": "Margaret Atwood", "release_date": "1985-06-01", "page_count": 311}
  599             {"index":{"_id": "Starship Troopers"}}
  600             {"name": "Starship Troopers", "author": "Robert A. Heinlein", "release_date": "1959-12-01", "page_count": 335}
  601             {"index":{"_id": "The Left Hand of Darkness"}}
  602             {"name": "The Left Hand of Darkness", "author": "Ursula K. Le Guin", "release_date": "1969-06-01", "page_count": 304}
  603             {"index":{"_id": "The Moon is a Harsh Mistress"}}
  604             {"name": "The Moon is a Harsh Mistress", "author": "Robert A. Heinlein", "release_date": "1966-04-01", "page_count": 288}
  605 '''
  606 buildRestTests.setups['sensor_rollup_job'] = '''
  607   - do:
  608       indices.create:
  609         index: sensor-1
  610         body:
  611           settings:
  612             number_of_shards: 1
  613             number_of_replicas: 0
  614           mappings:
  615             _doc:
  616               properties:
  617                 timestamp:
  618                   type: date
  619                 temperature:
  620                   type: long
  621                 voltage:
  622                   type: float
  623                 node:
  624                   type: keyword
  625   - do:
  626       raw:
  627         method: PUT
  628         path: _xpack/rollup/job/sensor
  629         body:  >
  630             {
  631                 "index_pattern": "sensor-*",
  632                 "rollup_index": "sensor_rollup",
  633                 "cron": "*/30 * * * * ?",
  634                 "page_size" :1000,
  635                 "groups" : {
  636                   "date_histogram": {
  637                     "field": "timestamp",
  638                     "interval": "1h",
  639                     "delay": "7d"
  640                   },
  641                   "terms": {
  642                     "fields": ["node"]
  643                   }
  644                 },
  645                 "metrics": [
  646                     {
  647                         "field": "temperature",
  648                         "metrics": ["min", "max", "sum"]
  649                     },
  650                     {
  651                         "field": "voltage",
  652                         "metrics": ["avg"]
  653                     }
  654                 ]
  655             }
  656 '''
  657 buildRestTests.setups['sensor_started_rollup_job'] = '''
  658   - do:
  659       indices.create:
  660         index: sensor-1
  661         body:
  662           settings:
  663             number_of_shards: 1
  664             number_of_replicas: 0
  665           mappings:
  666             _doc:
  667               properties:
  668                 timestamp:
  669                   type: date
  670                 temperature:
  671                   type: long
  672                 voltage:
  673                   type: float
  674                 node:
  675                   type: keyword
  676 
  677   - do:
  678       bulk:
  679         index: sensor-1
  680         type: _doc
  681         refresh: true
  682         body: |
  683           {"index":{}}
  684           {"timestamp": 1516729294000, "temperature": 200, "voltage": 5.2, "node": "a"}
  685           {"index":{}}
  686           {"timestamp": 1516642894000, "temperature": 201, "voltage": 5.8, "node": "b"}
  687           {"index":{}}
  688           {"timestamp": 1516556494000, "temperature": 202, "voltage": 5.1, "node": "a"}
  689           {"index":{}}
  690           {"timestamp": 1516470094000, "temperature": 198, "voltage": 5.6, "node": "b"}
  691           {"index":{}}
  692           {"timestamp": 1516383694000, "temperature": 200, "voltage": 4.2, "node": "c"}
  693           {"index":{}}
  694           {"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"}
  695 
  696   - do:
  697       raw:
  698         method: PUT
  699         path: _xpack/rollup/job/sensor
  700         body:  >
  701             {
  702                 "index_pattern": "sensor-*",
  703                 "rollup_index": "sensor_rollup",
  704                 "cron": "* * * * * ?",
  705                 "page_size" :1000,
  706                 "groups" : {
  707                   "date_histogram": {
  708                     "field": "timestamp",
  709                     "interval": "1h",
  710                     "delay": "7d"
  711                   },
  712                   "terms": {
  713                     "fields": ["node"]
  714                   }
  715                 },
  716                 "metrics": [
  717                     {
  718                         "field": "temperature",
  719                         "metrics": ["min", "max", "sum"]
  720                     },
  721                     {
  722                         "field": "voltage",
  723                         "metrics": ["avg"]
  724                     }
  725                 ]
  726             }
  727   - do:
  728       raw:
  729         method: POST
  730         path: _xpack/rollup/job/sensor/_start
  731 '''
  732 
  733 buildRestTests.setups['sensor_index'] = '''
  734   - do:
  735       indices.create:
  736         index: sensor-1
  737         body:
  738           settings:
  739             number_of_shards: 1
  740             number_of_replicas: 0
  741           mappings:
  742             _doc:
  743               properties:
  744                 timestamp:
  745                   type: date
  746                 temperature:
  747                   type: long
  748                 voltage:
  749                   type: float
  750                 node:
  751                   type: keyword
  752                 load:
  753                   type: double
  754                 net_in:
  755                   type: long
  756                 net_out:
  757                   type: long
  758                 hostname:
  759                   type: keyword
  760                 datacenter:
  761                   type: keyword
  762 '''
  763 
  764 buildRestTests.setups['sensor_prefab_data'] = '''
  765   - do:
  766       indices.create:
  767         index: sensor-1
  768         body:
  769           settings:
  770             number_of_shards: 1
  771             number_of_replicas: 0
  772           mappings:
  773             _doc:
  774               properties:
  775                 timestamp:
  776                   type: date
  777                 temperature:
  778                   type: long
  779                 voltage:
  780                   type: float
  781                 node:
  782                   type: keyword
  783   - do:
  784       indices.create:
  785         index: sensor_rollup
  786         body:
  787           settings:
  788             number_of_shards: 1
  789             number_of_replicas: 0
  790           mappings:
  791             _doc:
  792               properties:
  793                 node.terms.value:
  794                   type: keyword
  795                 temperature.sum.value:
  796                   type: double
  797                 temperature.max.value:
  798                   type: double
  799                 temperature.min.value:
  800                   type: double
  801                 timestamp.date_histogram.time_zone:
  802                   type: keyword
  803                 timestamp.date_histogram.interval:
  804                   type: keyword
  805                 timestamp.date_histogram.timestamp:
  806                   type: date
  807                 timestamp.date_histogram._count:
  808                   type: long
  809                 voltage.avg.value:
  810                   type: double
  811                 voltage.avg._count:
  812                   type: long
  813                 _rollup.id:
  814                   type: keyword
  815                 _rollup.version:
  816                   type: long
  817               _meta:
  818                 _rollup:
  819                   sensor:
  820                     cron: "* * * * * ?"
  821                     rollup_index: "sensor_rollup"
  822                     index_pattern: "sensor-*"
  823                     timeout: "20s"
  824                     page_size: 1000
  825                     groups:
  826                       date_histogram:
  827                         delay: "7d"
  828                         field: "timestamp"
  829                         interval: "60m"
  830                         time_zone: "UTC"
  831                       terms:
  832                         fields:
  833                           - "node"
  834                     id: sensor
  835                     metrics:
  836                       - field: "temperature"
  837                         metrics:
  838                           - min
  839                           - max
  840                           - sum
  841                       - field: "voltage"
  842                         metrics:
  843                           - avg
  844 
  845   - do:
  846       bulk:
  847         index: sensor_rollup
  848         type: _doc
  849         refresh: true
  850         body: |
  851           {"index":{}}
  852           {"node.terms.value":"b","temperature.sum.value":201.0,"temperature.max.value":201.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":201.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":5.800000190734863,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516640400000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  853           {"index":{}}
  854           {"node.terms.value":"c","temperature.sum.value":200.0,"temperature.max.value":200.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":200.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":4.199999809265137,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516381200000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  855           {"index":{}}
  856           {"node.terms.value":"a","temperature.sum.value":202.0,"temperature.max.value":202.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":202.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":5.099999904632568,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516554000000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  857           {"index":{}}
  858           {"node.terms.value":"a","temperature.sum.value":200.0,"temperature.max.value":200.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":200.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":5.199999809265137,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516726800000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  859           {"index":{}}
  860           {"node.terms.value":"b","temperature.sum.value":198.0,"temperature.max.value":198.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":198.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":5.599999904632568,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516467600000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  861           {"index":{}}
  862           {"node.terms.value":"c","temperature.sum.value":202.0,"temperature.max.value":202.0,"timestamp.date_histogram.time_zone":"UTC","temperature.min.value":202.0,"timestamp.date_histogram._count":1,"timestamp.date_histogram.interval":"1h","_rollup.computed":["temperature.sum","temperature.min","voltage.avg","temperature.max","node.terms","timestamp.date_histogram"],"voltage.avg.value":4.0,"node.terms._count":1,"_rollup.version":1,"timestamp.date_histogram.timestamp":1516294800000,"voltage.avg._count":1.0,"_rollup.id":"sensor"}
  863 
  864 '''
  865 buildRestTests.setups['sample_job'] = '''
  866   - do:
  867       xpack.ml.put_job:
  868         job_id: "sample_job"
  869         body:  >
  870           {
  871             "description" : "Very basic job",
  872             "analysis_config" : {
  873               "bucket_span":"10m",
  874               "detectors" :[
  875               {
  876                 "function": "count"
  877               }
  878             ]},
  879             "data_description" : {
  880               "time_field":"timestamp",
  881               "time_format": "epoch_ms"
  882             }
  883           }
  884 '''
  885 buildRestTests.setups['farequote_index'] = '''
  886   - do:
  887         indices.create:
  888           index: farequote
  889           body:
  890             settings:
  891               number_of_shards: 1
  892               number_of_replicas: 0
  893             mappings:
  894               metric:
  895                 properties:
  896                   time:
  897                     type: date
  898                   responsetime:
  899                     type: float
  900                   airline:
  901                      type: keyword
  902                   doc_count:
  903                      type: integer       
  904 '''
  905 buildRestTests.setups['farequote_data'] = buildRestTests.setups['farequote_index'] + '''
  906   - do:
  907         bulk:
  908           index: farequote
  909           type: metric
  910           refresh: true
  911           body: |
  912             {"index": {"_id":"1"}}
  913             {"airline":"JZA","responsetime":990.4628,"time":"2016-02-07T00:00:00+0000", "doc_count": 5}
  914             {"index": {"_id":"2"}}
  915             {"airline":"JBU","responsetime":877.5927,"time":"2016-02-07T00:00:00+0000", "doc_count": 23}
  916             {"index": {"_id":"3"}}            
  917             {"airline":"KLM","responsetime":1355.4812,"time":"2016-02-07T00:00:00+0000", "doc_count": 42}
  918 '''
  919 buildRestTests.setups['farequote_job'] = buildRestTests.setups['farequote_data'] + '''
  920   - do:
  921       xpack.ml.put_job:
  922         job_id: "farequote"
  923         body:  >
  924           {
  925             "analysis_config": {
  926               "bucket_span": "60m",
  927               "detectors": [{
  928                 "function": "mean",
  929                 "field_name": "responsetime",
  930                 "by_field_name": "airline"
  931               }],
  932             "summary_count_field_name": "doc_count"
  933             },
  934             "data_description": {
  935               "time_field": "time"
  936             }
  937           }
  938 '''
  939 buildRestTests.setups['farequote_datafeed'] = buildRestTests.setups['farequote_job'] + '''
  940   - do:
  941       xpack.ml.put_datafeed:
  942         datafeed_id: "datafeed-farequote"
  943         body:  >
  944           {
  945           "job_id":"farequote",
  946           "indexes":"farequote"
  947           }
  948 '''          
  949 buildRestTests.setups['server_metrics_index'] = '''
  950   - do:
  951         indices.create:
  952           index: server-metrics
  953           body:
  954             settings:
  955               number_of_shards: 1
  956               number_of_replicas: 0
  957             mappings:
  958               metric:
  959                 properties:
  960                   timestamp:
  961                     type: date
  962                   total:
  963                     type: long
  964 '''
  965 buildRestTests.setups['server_metrics_data'] = buildRestTests.setups['server_metrics_index'] + '''
  966   - do:
  967         bulk:
  968           index: server-metrics
  969           type: metric
  970           refresh: true
  971           body: |
  972             {"index": {"_id":"1177"}}
  973             {"timestamp":"2017-03-23T13:00:00","total":40476}
  974             {"index": {"_id":"1178"}}
  975             {"timestamp":"2017-03-23T13:00:00","total":15287}
  976             {"index": {"_id":"1179"}}
  977             {"timestamp":"2017-03-23T13:00:00","total":-776}
  978             {"index": {"_id":"1180"}}
  979             {"timestamp":"2017-03-23T13:00:00","total":11366}
  980             {"index": {"_id":"1181"}}
  981             {"timestamp":"2017-03-23T13:00:00","total":3606}
  982             {"index": {"_id":"1182"}}
  983             {"timestamp":"2017-03-23T13:00:00","total":19006}
  984             {"index": {"_id":"1183"}}
  985             {"timestamp":"2017-03-23T13:00:00","total":38613}
  986             {"index": {"_id":"1184"}}
  987             {"timestamp":"2017-03-23T13:00:00","total":19516}
  988             {"index": {"_id":"1185"}}
  989             {"timestamp":"2017-03-23T13:00:00","total":-258}
  990             {"index": {"_id":"1186"}}
  991             {"timestamp":"2017-03-23T13:00:00","total":9551}
  992             {"index": {"_id":"1187"}}
  993             {"timestamp":"2017-03-23T13:00:00","total":11217}
  994             {"index": {"_id":"1188"}}
  995             {"timestamp":"2017-03-23T13:00:00","total":22557}
  996             {"index": {"_id":"1189"}}
  997             {"timestamp":"2017-03-23T13:00:00","total":40508}
  998             {"index": {"_id":"1190"}}
  999             {"timestamp":"2017-03-23T13:00:00","total":11887}
 1000             {"index": {"_id":"1191"}}
 1001             {"timestamp":"2017-03-23T13:00:00","total":31659}
 1002 '''
 1003 buildRestTests.setups['server_metrics_job'] = buildRestTests.setups['server_metrics_data'] + '''
 1004   - do:
 1005       xpack.ml.put_job:
 1006         job_id: "total-requests"
 1007         body:  >
 1008           {
 1009             "description" : "Total sum of requests",
 1010             "analysis_config" : {
 1011               "bucket_span":"10m",
 1012               "detectors" :[
 1013               {
 1014                 "detector_description": "Sum of total",
 1015                 "function": "sum",
 1016                 "field_name": "total"
 1017               }
 1018             ]},
 1019             "data_description" : {
 1020               "time_field":"timestamp",
 1021               "time_format": "epoch_ms"
 1022             }
 1023           }
 1024 '''
 1025 buildRestTests.setups['server_metrics_datafeed'] = buildRestTests.setups['server_metrics_job'] + '''
 1026   - do:
 1027       xpack.ml.put_datafeed:
 1028         datafeed_id: "datafeed-total-requests"
 1029         body:  >
 1030           {
 1031           "job_id":"total-requests",
 1032           "indexes":"server-metrics"
 1033           }
 1034 '''
 1035 buildRestTests.setups['server_metrics_openjob'] = buildRestTests.setups['server_metrics_datafeed'] + '''
 1036   - do:
 1037       xpack.ml.open_job:
 1038         job_id: "total-requests"
 1039 '''
 1040 buildRestTests.setups['server_metrics_startdf'] = buildRestTests.setups['server_metrics_openjob'] + '''
 1041   - do:
 1042       xpack.ml.start_datafeed:
 1043         datafeed_id: "datafeed-total-requests"
 1044 '''
 1045 buildRestTests.setups['calendar_outages'] = '''
 1046   - do:
 1047         xpack.ml.put_calendar:
 1048           calendar_id: "planned-outages"
 1049 '''
 1050 buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages'] + '''
 1051   - do:
 1052         xpack.ml.post_calendar_events:
 1053           calendar_id: "planned-outages"
 1054           body: >
 1055             { "description": "event 1", "start_time": "2017-12-01T00:00:00Z", "end_time": "2017-12-02T00:00:00Z", "calendar_id": "planned-outages" }
 1056 
 1057 
 1058 '''
 1059 buildRestTests.setups['calendar_outages_openjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
 1060   - do:
 1061        xpack.ml.put_calendar:
 1062          calendar_id: "planned-outages"
 1063 '''
 1064 buildRestTests.setups['calendar_outages_addjob'] = buildRestTests.setups['server_metrics_openjob'] + '''
 1065   - do:
 1066        xpack.ml.put_calendar:
 1067          calendar_id: "planned-outages"
 1068          body:  >
 1069            {
 1070            "job_ids": ["total-requests"]
 1071            }
 1072 '''
 1073 buildRestTests.setups['calendar_outages_addevent'] = buildRestTests.setups['calendar_outages_addjob'] + '''
 1074   - do:
 1075        xpack.ml.post_calendar_events:
 1076          calendar_id: "planned-outages"
 1077          body:  >
 1078            { "events" : [
 1079            { "description": "event 1", "start_time": "1513641600000", "end_time": "1513728000000"},
 1080            { "description": "event 2", "start_time": "1513814400000", "end_time": "1513900800000"},
 1081            { "description": "event 3", "start_time": "1514160000000", "end_time": "1514246400000"}
 1082            ]}
 1083 '''
 1084 
 1085 // used by median absolute deviation aggregation
 1086 buildRestTests.setups['reviews'] = '''
 1087   - do:
 1088         indices.create:
 1089           index: reviews
 1090           body:
 1091             settings:
 1092               number_of_shards: 1
 1093               number_of_replicas: 0
 1094             mappings:
 1095               _doc:
 1096                 properties:
 1097                   product:
 1098                     type: keyword
 1099                   rating:
 1100                     type: long
 1101   - do:
 1102         bulk:
 1103           index: reviews
 1104           type: _doc
 1105           refresh: true
 1106           body: |
 1107             {"index": {"_id": "1"}}
 1108             {"product": "widget-foo", "rating": 1}
 1109             {"index": {"_id": "2"}}
 1110             {"product": "widget-foo", "rating": 5}
 1111 '''
 1112 
 1113 buildRestTests.setups['remote_cluster'] = buildRestTests.setups['host'] + '''
 1114   - do:
 1115       cluster.put_settings:
 1116         body:
 1117           persistent:
 1118             cluster.remote.remote_cluster.seeds: $transport_host
 1119 '''
 1120 
 1121 buildRestTests.setups['remote_cluster_and_leader_index'] = buildRestTests.setups['remote_cluster'] + '''
 1122   - do:
 1123       indices.create:
 1124         index: leader_index
 1125         body:
 1126           settings:
 1127             index.number_of_replicas: 0
 1128             index.number_of_shards: 1
 1129             index.soft_deletes.enabled: true
 1130 '''
 1131 
 1132 buildRestTests.setups['seats'] = '''
 1133   - do:
 1134         indices.create:
 1135           index: seats
 1136           body:
 1137             settings:
 1138               number_of_shards: 1
 1139               number_of_replicas: 0
 1140             mappings:
 1141               _doc:
 1142                 properties:
 1143                   theatre:
 1144                     type: keyword
 1145                   cost:
 1146                     type: long
 1147   - do:
 1148         bulk:
 1149           index: seats
 1150           type: _doc
 1151           refresh: true
 1152           body: |
 1153             {"index":{}}
 1154             {"theatre": "Skyline", "cost": 1}
 1155             {"index":{}}
 1156             {"theatre": "Graye", "cost": 5}
 1157             {"index":{}}
 1158             {"theatre": "Graye", "cost": 8}
 1159             {"index":{}}
 1160             {"theatre": "Skyline", "cost": 10}'''