Learn R Programming

elastic (version 0.3.0)

index: Index API operations

Description

Index API operations

Usage

index_get(index = NULL, features = NULL, raw = FALSE, verbose = TRUE,
  ...)

index_exists(index, ...)

index_delete(index, raw = FALSE, verbose = TRUE, ...)

index_create(index = NULL, body = NULL, raw = FALSE, verbose = TRUE, ...)

index_close(index, ...)

index_open(index, ...)

index_stats(index = NULL, metric = NULL, completion_fields = NULL, fielddata_fields = NULL, fields = NULL, groups = NULL, level = "indices", ...)

index_settings(index = "_all", ...)

index_status(index = NULL, ...)

index_segments(index = NULL, ...)

index_recovery(index = NULL, detailed = FALSE, active_only = FALSE, ...)

index_optimize(index = NULL, max_num_segments = NULL, only_expunge_deletes = FALSE, flush = TRUE, wait_for_merge = TRUE, ...)

index_upgrade(index = NULL, wait_for_completion = FALSE, ...)

index_analyze(text = NULL, field = NULL, index = NULL, analyzer = NULL, tokenizer = NULL, filters = NULL, char_filters = NULL, body = list(), ...)

index_flush(index = NULL, force = FALSE, full = FALSE, wait_if_ongoing = FALSE, ...)

index_clear_cache(index = NULL, filter = FALSE, filter_keys = NULL, fielddata = FALSE, query_cache = FALSE, id_cache = FALSE, ...)

Arguments

index
(character) A character vector of index names
features
(character) A character vector of features. One or more of settings, mappings, warmers or aliases
raw
If TRUE (default), data is parsed to list. If FALSE, then raw JSON.
verbose
If TRUE (default) the url call used printed to console.
...
Curl args passed on to POST, GET, PUT, HEAD, or
body
Query, either a list or json.
metric
(character) A character vector of metrics to display. Possible values: "_all", "completion", "docs", "fielddata", "filter_cache", "flush", "get", "id_cache", "indexing", "merge", "percolate", "refresh", "search", "segments", "store", "warmer".
completion_fields
(character) A character vector of fields for completion metric (supports wildcards)
fielddata_fields
(character) A character vector of fields for fielddata metric (supports wildcards)
fields
(character) Fields to add.
groups
(character) A character vector of search groups for search statistics.
level
(character) Return stats aggregated on "cluster", "indices" (default) or "shards"
detailed
(logical) Whether to display detailed information about shard recovery. Default: FALSE
active_only
(logical) Display only those recoveries that are currently on-going. Default: FALSE
max_num_segments
(character) The number of segments the index should be merged into. Default: "dynamic"
only_expunge_deletes
(logical) Specify whether the operation should only expunge deleted documents
flush
(logical) Specify whether the index should be flushed after performing the operation. Default: TRUE
wait_for_merge
(logical) Specify whether the request should block until the merge process is finished. Default: TRUE
wait_for_completion
(logical) Should the request wait for the upgrade to complete. Default: FALSE
text
The text on which the analysis should be performed (when request body is not used)
field
Use the analyzer configured for this field (instead of passing the analyzer name)
analyzer
The name of the analyzer to use
tokenizer
The name of the tokenizer to use for the analysis
filters
A character vector of filters to use for the analysis
char_filters
A character vector of character filters to use for the analysis
force
(logical) Whether a flush should be forced even if it is not necessarily needed ie. if no changes will be committed to the index.
full
(logical) If set to TRUE a new index writer is created and settings that have been changed related to the index writer will be refreshed.
wait_if_ongoing
If TRUE, the flush operation will block until the flush can be executed if another flush operation is already executing. The default is false and will cause an exception to be thrown on the shard level if another flush operation is already running. [1.4.0
filter
(logical) Clear filter caches
filter_keys
(character) A vector of keys to clear when using the filter_cache parameter (default: all)
fielddata
(logical) Clear field data
query_cache
(logical) Clear query caches
id_cache
(logical) Clear ID caches for parent/child

Details

index_analyze: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-analyze.html This method can accept a string of text in the body, but this function passes it as a parameter in a GET request to simplify.

index_flush: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-flush.html From the ES website: The flush process of an index basically frees memory from the index by flushing data to the index storage and clearing the internal transaction log. By default, Elasticsearch uses memory heuristics in order to automatically trigger flush operations as required in order to clear memory.

index_status: The API endpoint for this function was deprecated in Elasticsearch v1.2.0, and will likely be removed soon. Use index_recovery instead.

References

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices.html

Examples

Run this code
# get information on an index
index_get(index='shakespeare')
index_get(index='shakespeare', features=c('settings','mappings'))
index_get(index='shakespeare', features='aliases')
index_get(index='shakespeare', features='warmers')

# check for index existence
index_exists(index='shakespeare')
index_exists(index='plos')

# delete an index
index_delete(index='plos')

# create an index
index_create(index='twitter')
index_create(index='things')

## with a body
body <- '{
 "settings" : {
  "index" : {
    "number_of_shards" : 3,
    "number_of_replicas" : 2
   }
 }
}'
index_create(index='alsothat', body=body)

## with mappings
body <- '{
 "mappings": {
   "record": {
     "properties": {
       "location" : {"type" : "geo_point"}
      }
   }
 }
}'
index_create(index='gbifnewgeo', body=body)
gbifgeo <- system.file("examples", "gbif_geosmall.json", package = "elastic")
docs_bulk(gbifgeo)

# close an index
index_close('plos')

# open an index
index_open('plos')

# Get status of an index
index_status('plos')
index_status(c('plos','gbif'))

# Get stats on an index
index_stats('plos')
index_stats(c('plos','gbif'))
index_stats(c('plos','gbif'), metric='refresh')
index_stats('shakespeare', metric='completion')
index_stats('shakespeare', metric='completion', completion_fields = "completion")
index_stats('shakespeare', metric='fielddata')
index_stats('shakespeare', metric='fielddata', fielddata_fields = "evictions")
index_stats('plos', level="indices")
index_stats('plos', level="cluster")
index_stats('plos', level="shards")

# Get segments information that a Lucene index (shard level) is built with
index_segments()
index_segments('plos')
index_segments(c('plos','gbif'))

# Get recovery information that provides insight into on-going index shard recoveries
index_recovery()
index_recovery('plos')
index_recovery(c('plos','gbif'))
index_recovery("plos", detailed = TRUE)
index_recovery("plos", active_only = TRUE)

# Optimize an index, or many indices
index_optimize('plos')
index_optimize(c('plos','gbif'))

# Upgrade one or more indices to the latest format. The upgrade process converts any
# segments written with previous formats.
index_upgrade('plos')
index_upgrade(c('plos','gbif'))

# Performs the analysis process on a text and return the tokens breakdown of the text.
index_analyze(text = 'this is a test', analyzer='standard')
index_analyze(text = 'this is a test', analyzer='whitespace')
index_analyze(text = 'this is a test', analyzer='stop')
index_analyze(text = 'this is a test', tokenizer='keyword', filters='lowercase')
index_analyze(text = 'this is a test', tokenizer='keyword', filters='lowercase',
   char_filters='html_strip')
index_analyze(text = 'this is a test', index = 'plos')
index_analyze(text = 'this is a test', index = 'shakespeare')
index_analyze(text = 'this is a test', index = 'shakespeare', config=verbose())

## NGram tokenizer
body <- '{
        "settings" : {
             "analysis" : {
                 "analyzer" : {
                     "my_ngram_analyzer" : {
                         "tokenizer" : "my_ngram_tokenizer"
                     }
                 },
                 "tokenizer" : {
                     "my_ngram_tokenizer" : {
                         "type" : "nGram",
                         "min_gram" : "2",
                         "max_gram" : "3",
                         "token_chars": [ "letter", "digit" ]
                     }
                 }
             }
      }
}'
tokenizer_set(index = "shakespeare", body=body)
index_analyze(text = "art thouh", index = "shakespeare", analyzer='my_ngram_analyzer')

# Explicitly flush one or more indices.
index_flush()
index_flush(index = "plos")
index_flush(index = "shakespeare")
index_flush(index = c("plos","shakespeare"))
index_flush(wait_if_ongoing = TRUE)
library('httr')
index_flush(config=verbose())

# Clear either all caches or specific cached associated with one ore more indices.
index_clear_cache()
index_clear_cache(index = "plos")
index_clear_cache(index = "shakespeare")
index_clear_cache(index = c("plos","shakespeare"))
index_clear_cache(filter = TRUE)
library('httr')
index_clear_cache(config=verbose())

# Index settings
index_settings()
index_settings("_all")
index_settings('gbif')
index_settings(c('gbif','plos'))
index_settings('*s')

Run the code above in your browser using DataLab