300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Elasticsearch 字段可以模糊查询也可完全匹配查询(实例)

Elasticsearch 字段可以模糊查询也可完全匹配查询(实例)

时间:2020-08-04 22:10:48

相关推荐

Elasticsearch 字段可以模糊查询也可完全匹配查询(实例)

需求:

比如创建用户, 需要判断name是否重复后, 没有重复才插入数据, 创建好之后又需要模糊查询用户昵称name.

这时候name字段类型就需要具备分词并且可完全匹配搜索.

直接上代码:

创建映射mapping:

{"mapping": {"properties": {"class": {"type": "byte"},"dateline": {"type": "integer"},"gallery_num": {"type": "integer"},"id": {"type": "keyword"},"is_deleted": {"type": "byte"},"is_enabled": {"type": "byte"},"name": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}},"analyzer": "ik_smart"},"owner_id": {"type": "integer"},"owner_type": {"type": "byte"},"type": {"type": "byte"},"uptime": {"type": "integer"}}}}原文地址: websites_CSDN /wuchengzeng/article/details/108360899

执行搜索: 假设index为user.

curl -XPOST "http://elasticsearch:9200/user/_search" -H 'Content-Type: application/json' -d'{ "query": { "bool": {"must": { "match_phrase": {"name.keyword": "标签测试" }},"filter": [ {"term": { "owner_type": 1} }, {"term": { "is_enabled": 1} }, {"term": { "is_deleted": 0} }] } }}'

这样就实现了多字段查询以及name字段的完全匹配查询.

这里提供的是执行命令, 如果需要PHP代码, 可以留言.

Elasticsearch 字段可以模糊查询也可完全匹配查询(实例)_Websites-CSDN博客需求: 比如创建用户, 需要判断name是否重复后, 没有重复才插入数据, 创建好之后又需要模糊查询用户昵称name. 这时候name字段类型就需要具备分词并且可完全匹配搜索.直接上代码:创建映射mapping:{ "mapping": { "properties": { "class": { "type": "byte" }, "dateline": { "type": "integer" ./websites/article/details/108360899

本文地址: websites_CSDN /wuchengzeng/article/details/108360899

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。