了解了一下python对es 7.5的操作,记录下,不难:

  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. from settings import Config
  4. mapping = {
  5. 'properties': {
  6. 'topic': {
  7. 'type': 'text',
  8. 'analyzer': 'ik_max_word',
  9. 'search_analyzer': 'ik_max_word'
  10. },
  11. 'content': {
  12. 'type': 'text',
  13. 'analyzer': 'ik_max_word',
  14. 'search_analyzer': 'ik_max_word'
  15. },
  16. 'like': {
  17. 'type': 'integer'
  18. },
  19. 'read': {
  20. 'type': 'integer'
  21. }
  22. }
  23. }
  24.  
  25. data = {
  26. 'user':'xxx',
  27. 'topic':'44444',
  28. 'content':'xxxxxxxxxxxddddd',
  29. 'tm':'2019-1-20 22:00:00',
  30. 'like':'1',
  31. 'read':'2'
  32. }
  33.  
  34. #create index,create mapping
  35. Config.es.indices.delete(index='question', ignore=[400, 404])
  36. Config.es.indices.create(index='question', ignore=400)
  37. result = Config.es.indices.put_mapping(index='question', body=mapping)
  38. print(result)
  39.  
  40. #insert data
  41. result = Config.es.create(index='question', id=4, body=data)
  42.  
  43. #update document
  44. result = Config.es.index(index='question',body=data, id=4)
  45. print(result)
  1. #以下为查找操作
    #search index all content
  1. result = Config.es.search(index='question')
  2. print(result)
  3.  
  4. #query dsl,topic包含单词ddddd或lllll的所有内容
  5. dsl = {
  6. 'query': {
  7. 'match': {
  8. "topic": "ddddd lllll"
  9. }
  10. }
  11. }
  12.  
  13. result = Config.es.search(index='question', body=dsl)
  14. print(result)

    #kibana create index(mapping),post data
  1. PUT kb_question
  2. {
  3. "mappings":{
  4. "kb_question":{
  5. "properties": {
  6. "content": {
  7. "type": "text",
  8. "analyzer": "ik_max_word",
  9. "search_analyzer": "ik_max_word"
  10. },
  11. "topic": {
  12. "type": "text",
  13. "analyzer": "ik_max_word",
  14. "search_analyzer": "ik_max_word"
  15. },
  16. "like": {
  17. "type": "integer"
  18. },
  19. "read": {
  20. "type": "integer"
  21. },
  22. "user_id": {
  23. "type": "integer"
  24. },
  25. "user": {
  26. "type": "text"
  27. },
  28. "tm":{
  29. "type":"date",
  30. "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
  31. }
  32. }
  33. }
  34. }
  35. }
  36. POST kb_question/kb_question/
  37. {
  38. "user": "xiqing",
  39. "user_id": "704981",
  40. "topic": "test test",
  41. "content": "ccccccccccccccc la la lala la la la la la!!",
  42. "read":"0",
  43. "like":"0",
  44. "tm":"2019-1-20 15:45:00"
  45. }
  46. GET _cat/indices/kb_question
  47. #DELETE /kb_question
  48. PUT kb_answer
  49. { "mappings":{
  50. "kb_answer":{
  51. "properties": {
  52. "user": {
  53. "type": "text"
  54. },
  55. "q_id": {
  56. "type": "integer"
  57. },
  58. "answer": {
  59. "type": "text",
  60. "analyzer": "ik_max_word",
  61. "search_analyzer": "ik_max_word"
  62. },
  63. "like": {
  64. "type": "integer"
  65. },
  66. "tm":{
  67. "type":"date",
  68. "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
  69. }
  70. }
  71. }
  72. }
  73. }
  74. GET _cat/indices/kb_answer
  75. POST kb_answer/kb_answer/
  76. {
  77. "user": "xiqing",
  78. "q_id": "888",
  79. "answer": "answer2 answer2 answer2 answer2 answer2!!",
  80. "like":0,
  81. "tm":"2019-1-21 18:45:00"
  82. }

ES增删改查的更多相关文章

  1. ES增删改查入门1

    1.RESTful接口使用方法 为了方便直观我们使用Head插件提供的接口进行演示,实际上内部调用的RESTful接口. RESTful接口URL的格式: http://localhost:9200/ ...

  2. [elk]es增删改查最佳实战

    PUT app01 GET app01/_settings GET _all/_settings PUT app01/_settings { "number_of_replicas" ...

  3. 【ES】ElasticSearch初体验之使用Java进行最基本的增删改查~

    好久没写博文了, 最近项目中使用到了ElaticSearch相关的一些内容, 刚好自己也来做个总结. 现在自己也只能算得上入门, 总结下自己在工作中使用Java操作ES的一些小经验吧. 本文总共分为三 ...

  4. Es学习第三课, ElasticSearch基本的增删改查

    前面两课我们了解了ES的基本概念并且学会了安装ES,这节课我们就来讲讲ES基本的增删改查:ES主要对外界提供的是REST风格的API,我们通过客户端操作ES本质上就是API的调用.在第一课我们就讲了索 ...

  5. kibana的Dev Tool中如何对es进行增删改查

    kinaba Dev Tool中对es(elasticSearch)进行增删改查 一.查询操作 查询语句基本语法 以下语句类似于mysql的: select * from  xxx.yyy.topic ...

  6. Es图形化软件使用之ElasticSearch-head、Kibana,Elasticsearch之-倒排索引操作、映射管理、文档增删改查

    今日内容概要 ElasticSearch之-ElasticSearch-head ElasticSearch之-安装Kibana Elasticsearch之-倒排索引 Elasticsearch之- ...

  7. elasticsearch索引的增删改查入门

    为了方便直观我们使用Head插件提供的接口进行演示,实际上内部调用的RESTful接口. RESTful接口URL的格式: http://localhost:9200/<index>/&l ...

  8. 分布式搜索elasticsearch 索引文档的增删改查 入门

    1.RESTful接口使用方法 为了方便直观我们使用Head插件提供的接口进行演示,实际上内部调用的RESTful接口. RESTful接口URL的格式: http://localhost:9200/ ...

  9. ElasticSearch6(三)-- Java API实现简单的增删改查

    基于ElasticSearch6.2.4, Java API创建索引.查询.修改.删除,pom依赖和获取es连接 可查看此文章. package com.xsjt.learn; import java ...

随机推荐

  1. noip13

    T1 一开始直接丢了个暴力走人50pts,然后开始打表找规律,啥也没找着,最后二十分钟突然看出来了什么,把 \(f_{n,m}\)式子列了一下,发现常数项没啥规律,最后五分钟,突然闪过一丝灵感,但是是 ...

  2. jpa 指定字段内容按照顺序排序(orderBy when then)

    query.orderBy( criteriaBuilder.desc( criteriaBuilder.selectCase() .when(criteriaBuilder.equal(root.g ...

  3. 堆排序——Java实现

    一.堆排序 堆排序(Heap Sort)是指利用堆这种数据结构所设计的一种排序算法.堆是一个近似完全二叉树的结构,并同时满足堆积的性质:即子结点的键值或索引总是小于(或者大于)它的父节点. 二.堆 什 ...

  4. 十八:使用JDBC进行批处理

    一.使用Statement完成批处理 1.使用Statement对象添加要批量执行SQL语句,如下: 1 Statement.addBatch(sql1); 2 Statement.addBatch( ...

  5. springmvc学习日志四

    一.回顾 1.文件上传 1.1引入fileupload的jar包 1.2在springmvc的配置文件中引入CommonsMutilpartResolver文件上传解析器 1.3在控制层在写入代码 2 ...

  6. spring知识点(面试题)

    转自(参考):https://baijiahao.baidu.com/s?id=1595722523154435312&wfr=spider&for=pc 本人收集了一些在大家在面试时 ...

  7. spring之自定义注解

    java.lang.annotation提供了四种元注解,专门注解其他的注解: @Target –注解用于什么地方,默认值为任何元素,表示该注解用于什么地方.可用的ElementType指定参数 ,也 ...

  8. springboot全局异常封装案例

    @ControllerAdvice三个场景:>https://www.cnblogs.com/lenve/p/10748453.html 全局异常处理 全局数据绑定 全局数据预处理 首先定义一个 ...

  9. Linux命令集锦之·字符截取命令

    时间:2018-11-15 记录:byzqy 字符截取命令: cut.printf.awk.sed cut $ cut [选项] 文件名 选项: -f 列号:提取第几列: -d 分隔符:按照指定分隔符 ...

  10. hibernate01

    什么是hibernate ORM框架/持久层框架 jdbc的一个框架 object reference mapping 通过管理对象来改变数据库中的数据 通过管理对象来操作数据库 hibernate的 ...