Skip to content

Latest commit

 

History

History
131 lines (121 loc) · 2.84 KB

README.md

File metadata and controls

131 lines (121 loc) · 2.84 KB

Spring and ElasticSearch

This is simple application with elasticsearch and springboot 2.0

Things done

  • Elasticsearch index with 2 types analyzers

To start application

  1. Start 2 instances of elasticsearch
$ docker-compose -f docker-compose.yml up
  1. Create template
$ curl -XPOST -H 'Content-Type: application/json' http://localhost:9200/_template/template_name -d '{
  "index_patterns": ["ngram_test_*"],
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": {
          "type":      "custom",
          "tokenizer": "my_tokenizer",
          "filter": [
            "lowercase"
          ]
        }
      },"tokenizer": {
        "my_tokenizer": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 10,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      }
	},
  "number_of_shards": 2
  },
  "mappings": {
    "_doc": {
      "dynamic": false,
      "properties": {
        "name": {
          "type": "text",
          "fielddata": true,
          "analyzer" : "my_custom_analyzer"
        }
      }
    }
  }
}'
  1. Create first index
$ curl -XPUT http://localhost:9200/ngram_test_1
  1. Create second template
$ curl -XPOST -H 'Content-Type: application/json' http://localhost:9200/_template/template_name -d '{
  "index_patterns": [
    "search_test_*"
  ],
  "settings": {
    "analysis": {
      "analyzer": {
        "my_custom_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase"
          ]
        }
      }
    },
    "number_of_shards": 2
  },
  "mappings": {
    "type": {
      "dynamic": false,
      "properties": {
        "name": {
          "type": "text",
          "fielddata": true
        },
        "options": {
          "type": "nested",
          "dynamic": false,
          "properties": {
            "name": {
              "type": "keyword"
            },
            "value": {
              "type": "text",
              "fielddata": true,
              "analyzer": "my_custom_analyzer"
            }
          }
        }
      }
    }
  }
}'
  1. Create second index
$ curl -XPUT http://localhost:9200/search_test_1
  1. Start vagrant box (it will take a while to install java 10 )
$ vagrant up
  1. Use vagrant ssh to enter VM and go to /vagrant_data where project will be mounted. You have to provide ip address of machine with running elasticsearch:
$ vagrant ssh
$ cd /vagrant_data
$ ./start.sh IP_OF_HOST_WITH_ELASTIC
  1. Now you can use endpoints: