elasticsearch 6.0 analyze api example using curl

Elasticsearch Analyze API example using curl with simple steps.


In our example we will learn about analyze API using curl in Elasticsearch.Analyze API can be used to test the analysis process.It can be used to know how information is being stored in Elasticsearch indices.using this API we can specify any text to Elasticsearch and in return it gives us analyzed tokens.

cURL is a command line tool that can be used to transfer data over HTTP.In our example we will execute cURL command from cygwin.

  • In our example we will execute below cURL command to analyze the text.
  • curl -XGET 'localhost:9200/_analyze?pretty' -H 'Content-Type: application/json' -d'
    {
      "analyzer" : "standard",
      "text" : "Learning Elasticsearch Analyze API from preparationforinterview"
    }'
    


  • In our example we have used standard analyzer which will return each token in lowercase. In standard analyzer punctuation at the end of sentence is removed.

Note :

If we have any analyzer in elasticsearch.yml that also can be referred by its name

If we have any custom analyzer in index that also can used in our analyzer as shown below

curl -XGET 'localhost:9200/preparationforinterview/_analyze?pretty' -H 'Content-Type: application/json' -d'
{
  "analyzer" : "myCustomAnalyzer",
  "text" : "Learning Elasticsearch Analyze API from preparationforinterview"
}'

If we have any analyzer associated with any field of index, we can also refer that analyzer.

curl -XGET 'localhost:9200/preparationforinterview/_analyze?pretty' -H 'Content-Type: application/json' -d'
{
  "field" : "profession",
  "text" : "Learning Elasticsearch Analyze API from preparationforinterview"
}'

Combining parts for custom analyzer

Sometime we may not want built in analyzer but we want to add our filter and tokenizers as per our requirement.For example in our example we are mentioning that create token based on whitespace and convert tokens into uppercase after that reverse it.

curl -XGET 'localhost:9200/_analyze?pretty' -H 'Content-Type: application/json' -d'
{
  "tokenizer" : "whitespace",
  "filter" : ["uppercase","reverse"],
  "text" : "Learning Elasticsearch Analyze API from preparationforinterview"
}'


_termvector

_termvector is used to get information of terms in certain document, for example frequency in a document, index etc.In our example we are executing below command for particular field (In my Elasticsearch i have already data that was indexed earlier.)

curl -XGET 'localhost:9200/preparationforinterview/elasticsearch/6/_termvectors?fields=profession&pretty=true'





Visit Others Links

Elasticsearch Introduction
Elasticsearch 6.0 Setup
Elasticsearch Indexing And Searching
Elasticsearch 6.0 indexing example using curl
Elasticsearch 6.0 searching example using curl
Elasticsearch 6.0 updating example using curl
Elasticsearch 6.0 updating example using curl when document does not exist
Elasticsearch 6.0 deleting example using curl
Elasticsearch 6.0 request body based searching
Elasticsearch 6.0 query component example
Elasticsearch 6.0 Analyze API example
Top Elasticsearch Interview Question
© 2019 PreparationForInterview.com