码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Elasticsearch7.5.2 常用rest api与elasticsearch库


    目录

    一、rest api

    1. 新建索引

    2. 删除索引

    3. 插入单条数据

    4. 更新单条数据

    5. 删除单条数据

    6. 查询数据

    二、python elasticsearch库

    1. 新建索引


    一、rest api

    1. 新建索引

    请求方式:PUT

    请求URL:http://ip/(your_index_name)

    示例URL:http://ip/test_log_20240710-0

     数据参数:

    1. params = {
    2. "settings": {
    3. "number_of_shards": 1,
    4. "number_of_replicas": 0
    5. },
    6. "aliases": {
    7. "test_log":{}
    8. },
    9. "mappings": {
    10. "properties": {
    11. "create_time": {
    12. "type": "date"
    13. },
    14. "status":{"type": "integer"},
    15. "dev_ip":{"type": "ip"},
    16. "dev_uuid":{"type": "keyword"},
    17. "user": {
    18. "properties": {
    19. "name": {
    20. "type": "text"
    21. },
    22. "age": {
    23. "type": "integer"
    24. },
    25. "email": {
    26. "type": "keyword"
    27. }
    28. }
    29. },
    30. "infos": {
    31. "type": "nested",
    32. "dynamic": false,
    33. "properties": {
    34. "v_id": {"type": "keyword"},
    35. "v_name": {"type": "keyword"},
    36. "v_desc": {"type": "text"}
    37. }
    38. },
    39. "remark": {"type": "text"},
    40. "show_num": {"type": "long", "doc_values": false, "index": false}
    41. }
    42. }
    43. }
    44. """
    45. 字段类型:
    46. text:用于全文本搜索,如文章内容。text字段会被分析器分词,支持模糊搜索和前缀搜索。
    47. keyword:用于不进行分词的搜索,适合存储关键词、ID、标签等。keyword字段不会被分词,适用于精确匹配和聚合。
    48. integer/long/short/byte/double/float/half_float/scaled_float:用于数值类型的数据,不同的类型对应不同的数值范围和精度。
    49. boolean:布尔型字段,值只能是true或false。
    50. binary:用于存储二进制数据,如图像或文件。
    51. date:日期时间字段,可以使用ISO8601格式的字符串或毫秒级的时间戳。
    52. date_nanos:纳秒精度的日期时间字段,存储为纳秒时间戳。
    53. ip:用于存储IPv4或IPv6地址。
    54. object:用于嵌套的JSON对象。可以定义内部字段的映射。
    55. nested:用于存储复杂结构的嵌套文档,允许对嵌套文档进行独立索引和搜索。
    56. geo_point:用于地理坐标,支持基于地理位置的查询。
    57. geo_shape:用于地理形状,如多边形,支持更复杂的地理查询。
    58. completion:用于自动补全功能,存储经过分析的词条列表。
    59. constant_keyword:与keyword类似,但值在索引时会被复制到所有分片,加速聚合操作。
    60. token_count:用于存储分词后的词数。
    61. """

    2. 删除索引

    请求方式:DELETE

    请求URL:http://ip/(your_index_name)

    示例URL:http://ip/test_log_20240710-0

    3. 插入单条数据

    请求方式:POST

    请求URL:http://ip/(your_index_name)

    示例URL:http://ip/test_log_20240710-0

    数据参数:

    1. {
    2. "create_time": 1720601022255,
    3. "status": 201,
    4. "dev_ip": "192.168.1.101",
    5. "dev_uuid": "123e4567e89b12d3a456426614174000",
    6. "user": {
    7. "name": "战三",
    8. "age": 30,
    9. "email": "zhansan@example.com"
    10. },
    11. "infos": [
    12. {
    13. "v_id": "123e4567e89b12d3a456426614174000",
    14. "v_name": "战三",
    15. "v_desc": "描述啦啦啦啦啦啦"
    16. }
    17. ],
    18. "remark": "描述!!!!!",
    19. "show_num": 6789
    20. }

    4. 更新单条数据

    请求方式:PUT

    请求URL:http://ip/(your_index_name)/_doc/(本条记录id)

    示例URL:http://ip/test_log_20240710-0/_doc/KjjOm5ABJ5wlHmqgfJvm

    数据参数:

    1. {
    2. "create_time": "2023-04-01T12:00:00Z",
    3. "status": 200,
    4. "dev_ip": "192.168.1.100",
    5. "dev_uuid": "123e4567-e89b-12d3-a456-426614174000",
    6. "user": {
    7. "name": "阿汉",
    8. "age": 30,
    9. "email": "john.doe@example.com"
    10. },
    11. "infos": [
    12. {
    13. "v_id": "info1",
    14. "v_name": "Info One",
    15. "v_desc": "This is the description of info one."
    16. },
    17. {
    18. "v_id": "info2",
    19. "v_name": "Info Two",
    20. "v_desc": "This is the description of info two."
    21. }
    22. ],
    23. "remark": "Additional remarks about this log entry.",
    24. "show_num": 12345
    25. }

    5. 删除单条数据

    请求方式:DELETE

    请求URL:http://ip/(your_index_name)/_doc/(本条记录id)

    示例URL:http://ip/test_log_20240710-0/_doc/KjjOm5ABJ5wlHmqgfJvm

    数据参数:无

    6. 查询数据

    请求方式:POST

    请求URL:http://ip/(your_index_name)/_search

    示例URL:http://ip/test_log_20240710-0/_search

    数据参数:

    1. {
    2. "size": 10,
    3. "query": {
    4. "bool": {
    5. "must": [
    6. {
    7. "term": {
    8. "status": 200
    9. }
    10. }
    11. ]
    12. }
    13. }
    14. }

    二、python elasticsearch库

    1. 新建索引

    ......

  • 相关阅读:
    易点易动固定资产管理系统:实现全生命周期闭环式管理和快速盘点
    树状数组及扩展
    USB Composite 组合设备之麦克风与扬声器
    centos通过docker快速搭建bWAPP
    Day5:三指针描述一颗树
    冒泡算法,leetcode第一题
    算法训练Day36 贪心算法系列 - 重叠区间问题 | LeetCode435. 无重叠区间;763. 划字母区间;56.合并区间
    记录一次IDEA非法字符‘\ufeff‘报错
    详解虚拟DOM的原理
    [compfest14 ctf 2022] 不知道哪国的网站,特别慢
  • 原文地址:https://blog.csdn.net/a961634066/article/details/140330886
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号