es用python增加字段_ES 增删改查操作

创建

自定义ID增加PUT /{index}/{type}/{id}

{

"field": "value",

...

}

自动增加ID使用post方式POST /website/blog/

{

"title": "My second blog entry",

"text": "Still trying this out...",

"date": "2014/01/01"

}

更新PUT /website/blog/123

{

"title": "My first blog entry",

"text": "Just trying this out...",

"date": "2014/01/01"

}我们能看到 Elasticsearch 已经增加了 _version 字段值,created 标志设置成 false ,是因为相同的索引、类型和 ID 的文档已经存在。

删除DELETE /website/blog/123如果找到该文档,Elasticsearch 将要返回一个 200 ok 的 HTTP 响应码

查询

search查询http://ip/_search 在所有索引中搜索全部类型

http://ip/索引/_search 在指定索引中搜索全部类型

http://ip/索引,索引/_search 搜索两个索引的全部文档

http://ip/索引*,索引*/_search 搜索以指定字符串开头的两个索引中的全部文档

http://ip/索引/索引类型/_search 搜索指定索引中指定索引类型的全部文档

http://ip/索引,索引/索引类型,索引类型/_search 搜索两个索引中,指定的两个索引类型的文档

http://ip/_all/索引类型,索引类型/_search 在所有索引中搜索两个指定的索引类型文档

http://ip/索引/索引类型/_search?q=name:立信&sort=id:desc 在指定索引中搜索指定数据,并按照id倒序排列

took:耗时毫秒,time_out:是否超时,hits.total:查询条数,hits.max_score:匹配分数

dsl查询查询所有文档,并按照id倒序排列GET /ecommerce/product/_search

{

"query": { "match_all": {} },

"sort": [

{ "id": "desc" }

],

"from": 0,

"size": 3

}

query:包装查询条件

sort:包装排序条件

form:第几页

size:每页几条根据名称查询,并按照id排序GET /ecommerce/product/_search

{

"query":{"macth":{"name":"测试"}},

"sort":[{"id":"desc"}]

}返回结果的指定列GET /ecommerce/product/_search

{

"query":{"match_all":{}},

"_source":["title","time"]

}

filter搜索指定名称的数据,而且id大于指定值GET /ecommerce/product/_search

{

"query" : {

"bool" : {

"must" : {

"match" : {

"title" : "立信"

}

},

"filter" : {

"range" : {

"id" : { "gt" : 10000 }

}

}

}

}

}

全文检索全文检索会将输入的搜索串拆解开来,去倒排索引里面去一一匹配,只要能匹配上任意一个拆解后的单词,就可以作为结果返回。根据一段文字进行查找GET /ecommerce/product/_search

{

"query" : {

"match" : {

"title" : "yagao producer"

}

}

}

精确查找输入的搜索串,必须在指定的字段文本中,完全包含一模一样的,才可以算匹配,作为结果返回。{

"query" : {

"match_phrase" : {

"title" : "yagao producer"

}

}

}

高亮显示{

"query" : {

"match_phrase" : {

"title" : "立信"

}

},

"highlight": {

"fields":{

"title": {}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Python中进行Elasticsearch的增删改查操作,你可以使用Elasticsearch的官方库elasticsearch-py来实现。下面是一个简单的例子来演示如何进行增删改查操作: 引用: 首先,你需要导入Elasticsearch库并连接到Elasticsearch服务器: ```python from elasticsearch import Elasticsearch # 连接到Elasticsearch服务器 es = Elasticsearch([ES_IP], http_auth=('elastic', '123456'), port=ES_PORT) ``` 引用: 查询数据: - 查询所有数据: ```python body = { "size": 111, # 最大显示数量,es默认展示10条 "query": { "match_all": {} } } res = es.search(index='my-index', body=body, request_timeout=30) ``` - 查询具体某个字段: ```python body = { "size": 10000, # 最大显示数量 "query": { "match": { "text": { "query": search_key, "analyzer": "ik_smart", # 用来指定搜索的词语按那种拆词粒度拆词 "operator": "or", # 按拆分后的词查询时,词与词之间是 and 还是 or 的关系 "minimum_should_match": "75%" # 该参数用来控制应该匹配的分词的最少数量,至少匹配几个词才召回查询的结果 } } } } res = es.search(index='my-index', body=body, request_timeout=30) ``` 引用: 获取拆分后的词: 你可以使用Elasticsearch的analyze API来获取拆分后的词,例如: ```python body = { "text": "惠普 p2015dn", "analyzer": "ik_max_word" } res = es.indices.analyze(index='my-index', body=body) key_list = [dic['token'] for dic in res['tokens']] print(key_list) # ['惠普', 'p2015dn', 'p', '2015', 'dn'] ``` 以上是关于在Python中使用Elasticsearch进行增删改查的基本操作。你可以根据具体的需求使用不同的查询方式,并根据返回的结果进行相应的处理。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [python 使用 Elasticsearch 增删查改](https://blog.csdn.net/Waller_/article/details/109810964)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值