elasticsearch
2022-05-18 本文已影响0人
hehehehe
docker run -d --name elasticsearch -v /Users/xxx/Downloads/tmp/docker/es/logs:/usr/share/elasticsearch/logs -v /Users/xxx/Downloads/tmp/docker/es/data:/usr/share/elasticsearch/data --net elastic -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.16.3
from elasticsearch import Elasticsearch
es = Elasticsearch(hosts='localhost:9200')
body = {
"settings": {
"number_of_shards": 5,
},
"mappings": {
"properties":{
"name": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart"
}
}
}
}
#创建 index
es.indices.create(index = "test2", body = body)
es.index(index='test2',body={"name":"今天是个好日子"})
es.index(index='test2',body={"name":"明天是个好日纸"})
es.index(index='test2',body={"name":"昨天是个好日纸"})
es.indices.get_mapping(index='test2')
es.search(index='test2',body={'query': { "match": {"name": "日"}}})