美文网首页
elasticsearch

elasticsearch

作者: hehehehe | 来源:发表于2022-05-18 14:27 被阅读0次
    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": "日"}}})
    

    相关文章

      网友评论

          本文标题:elasticsearch

          本文链接:https://www.haomeiwen.com/subject/tiraurtx.html