An open API service indexing awesome lists of open source software.

https://github.com/pipizhang/docker-elasticsearch-analysis-ik

Docker for Elasticsearch + IK Analysis
https://github.com/pipizhang/docker-elasticsearch-analysis-ik

docker elasticsearch ik-analyzer

Last synced: 11 months ago
JSON representation

Docker for Elasticsearch + IK Analysis

Awesome Lists containing this project

README

          

# Docker for Elasticsearch + IK Analysis

This is the Git repo of the Docker image for Elasticsearch + IK Analysis.

#### Getting started
A Quick Test
```bash
docker run --rm --name es -p 9200:9200 -p 9300:9300 peterzhang/elasticsearch-analysis-ik
```

Persist Elasticsearch data
```bash
docker run --rm --name es -p 9200:9200 -p 9300:9300 -v $(pwd)/data:/usr/share/elasticsearch/data peterzhang/elasticsearch-analysis-ik
```

#### Quick Example

1.create a index

```bash
curl -XPUT http://localhost:9200/index
```

2.create a mapping

```bash
curl -XPOST http://localhost:9200/index/fulltext/_mapping -H 'Content-Type:application/json' -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}

}'
```

3.index some docs

```bash
curl -XPOST http://localhost:9200/index/fulltext/1 -H 'Content-Type:application/json' -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'
```

```bash
curl -XPOST http://localhost:9200/index/fulltext/2 -H 'Content-Type:application/json' -d'
{"content":"公安部:各地校车将享最高路权"}
'
```

```bash
curl -XPOST http://localhost:9200/index/fulltext/3 -H 'Content-Type:application/json' -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
```

```bash
curl -XPOST http://localhost:9200/index/fulltext/4 -H 'Content-Type:application/json' -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'
```

4.query with highlighting

```bash
curl -XPOST http://localhost:9200/index/fulltext/_search -H 'Content-Type:application/json' -d'
{
"query" : { "match" : { "content" : "中国" }},
"highlight" : {
"pre_tags" : ["", ""],
"post_tags" : ["", ""],
"fields" : {
"content" : {}
}
}
}
'
```

Result

```json
{
"took": 14,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 2,
"hits": [
{
"_index": "index",
"_type": "fulltext",
"_id": "4",
"_score": 2,
"_source": {
"content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
},
"highlight": {
"content": [
"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首 "
]
}
},
{
"_index": "index",
"_type": "fulltext",
"_id": "3",
"_score": 2,
"_source": {
"content": "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
},
"highlight": {
"content": [
"均每天扣1艘中国渔船 "
]
}
}
]
}
}
```

#### Troubleshooting

1.virtual memory areas vm.max_map_count [65530] is too low

The vm.max_map_count setting should be set permanently in /etc/sysctl.conf or /etc/sysctl.d/?.conf:

```bash
$ grep vm.max_map_count /etc/sysctl.conf
vm.max_map_count=262144
```