随笔 - 1357  文章 - 0  评论 - 1104  阅读 - 1941万

elasticsearch——增删改查

复制代码
-- 创建索引
PUT /icon_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "text_anlyzer": { 
          "tokenizer": "ik_max_word",
          "filter": "py"
        },
        "completion_analyzer": {
          "tokenizer": "keyword", 
          "filter": "py"
        }
      },
      "filter": {
        "py": {
          "type": "pinyin",
          "keep_full_pinyin": false,
          "keep_joined_full_pinyin": true,
          "keep_original": true,
          "limit_first_letter_length": 16,
          "remove_duplicated_term": true,
          "none_chinese_pinyin_tokenize": false
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "id":{
        "type": "keyword"
      },
      "username":{
        "type": "text",
        "analyzer": "text_anlyzer",
        "search_analyzer": "ik_smart"
      },
      "category":{
        "type": "keyword"
      },
      "icon_score":{
        "type": "integer"
      },
      "create_time": { 
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
      }
    }
  }
}


--查询索引
GET /_cat/indices?v
get /icon_index/_search
get /icon_index/_mapping



--初始化数据
PUT /icon_index/_doc/1
{ 
    "username":"我是中国人,来自福建",
    "icon_score":9,
    "category":"仙侠",
    "create_time":"2019-04-26 01:59:54"
}

PUT /icon_index/_doc/2
{ 
    "username":"厦门水电费",
    "icon_score":7,
    "category":"回合",
    "create_time":"2019-06-10 01:59:54"
}

PUT /icon_index/_doc/3
{ 
    "username":"奥林匹克在中国举行",
    "icon_score":5,
    "category":"模拟",
    "create_time":"2019-05-18 01:59:54"
}

PUT /icon_index/_doc/4
{ 
    "username":"Java mysql 日语 应用",
    "icon_score":3,
    "category":"卡牌",
    "create_time":"2019-06-16 01:59:54"
}

PUT /icon_index/_doc/5
{ 
    "username":"币安欧意gate",
    "icon_score":1,
    "category":"仙侠",
    "create_time":"2019-07-15 01:59:54"
}

--组合查询
# username like '%名称%' and username like '%名称1%' 
# and score >= 10 and score <= 8 and category = '分类精确查询' 

# 匹配username包含中国或mysql,icon_score范围在6~10,category为仙侠
GET /icon_index/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "username": "中国 mysql"}},
        {
          "range": {
            "icon_score": { "gte": 6,"lte": 10 }
          }
        },
        { "term": { "category": "仙侠"}} 
      ]
    }
  }
}
复制代码

 

posted on   Ruthless  阅读(93)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
历史上的今天:
2020-04-23 Windows下安装VScode,并使用,以及中文配置
2019-04-23 ELK-log4j2异步输出+logstash
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示