markdown elasticsearch,快速入门,码头工具
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown elasticsearch,快速入门,码头工具相关的知识,希望对你有一定的参考价值。
# Quick Start
## How to install
``` Install ES docker
# pull image
docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2
# start ES container
docker run -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2
# access 9200 to ensure service up
curl -XGET 'localhost:9200'
```
## CURD demo (curl)
``` bash
# show all indexs
curl -XGET 'localhost:9200/_cat/indices?v'
# show all documents
curl -XGET 'localhost:9200/novels2/_search?pretty'
# show document by id
curl -XGET 'localhost:9200/novels2/authors/1?pretty'
# search document with wildcard
curl -XGET 'localhost:9200/novels2/_search?pretty'
-d '{"query":{"wildcard":{"name":"ja*"}}}'
-H 'Content-type:application/json'
```
## Python Way
```python
# create one record
In [5]: import json
In [7]: body = json.loads('{"name":"jack", "age":18}')
In [8]: from elasticsearch import Elasticsearch
In [9]: con = {"host":"localhost", "post":9200}
In [13]: con = [{"host": "localhost", "port":9200}]
In [14]: es = Elasticsearch(con)
In [17]: es.index(index='test', doc_type='people', id=1, body=body)
Out[17]:
{'_index': 'test',
'_type': 'people',
'_id': '1',
'_version': 1,
'result': 'created',
'_shards': {'total': 2, 'successful': 1, 'failed': 0},
'_seq_no': 0,
'_primary_term': 1}
# query a record
In [18]: es.get(index='test', doc_type='people', id=1)
Out[18]:
{'_index': 'test',
'_type': 'people',
'_id': '1',
'_version': 1,
'found': True,
'_source': {'name': 'jack', 'age': 18}}
# search record with wildcard
In [21]: es.search(index='test', body={"query": {"wildcard":{"name":"j*"}}})
Out[21]:
{'took': 48,
'timed_out': False,
'_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0},
'hits': {'total': 1,
'max_score': 1.0,
'hits': [{'_index': 'test',
'_type': 'people',
'_id': '1',
'_score': 1.0,
'_source': {'name': 'jack', 'age': 18}}]}}
# some other search type like
# prefix: search by rule as **start with**
# match: something like exactly match
```
## 坑
* 使用 wildcard 做 match 的时候, 由于目标字符串中有大些字母, 就用大写的去匹配, 结果失败, 用小写的去匹配就可以工作, 看了下别人的评论, 应该是和什么analyzed 有关
## docker compose command
## Source
[offical ES Website](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html)
以上是关于markdown elasticsearch,快速入门,码头工具的主要内容,如果未能解决你的问题,请参考以下文章
markdown [Mapping] #elasticsearch #snippets
markdown [索引]操作文档,索引#elasticsearch
markdown [CAT] #elasticsearch
markdown Elasticsearch备忘单
markdown elasticsearch / kibana起动
markdown 自动重启Elasticsearch