当前位置:   article > 正文

Elasticsearch(三) 使用kibana 操作ES_kibana es highlight无效果

kibana es highlight无效果

文档中包含语句

1,索引(新增 查询 删除)
2, mapping 创建
3,文档(新增,修改,删除,批量新增)
4,文档查询(基本查询,高级查询,分页,高亮,排序)

1,使用kibana 新增 查询 删除索引:

  1. 新增请求:
  2. PUT /goodsindex
  3. 返回:
  4. {
  5. "acknowledged" : true,
  6. "shards_acknowledged" : true,
  7. "index" : "goodsindex"
  8. }
  1. 查询请求:
  2. GET /goodsindex
  3. 返回:
  4. {
  5. "goodsindex" : {
  6. "aliases" : { },
  7. "mappings" : { },
  8. "settings" : {
  9. "index" : {
  10. "creation_date" : "1590992920969",
  11. "number_of_shards" : "5",
  12. "number_of_replicas" : "1",
  13. "uuid" : "FHD9se3qSY-0XOD2t6HprQ",
  14. "version" : {
  15. "created" : "6080099"
  16. },
  17. "provided_name" : "goodsindex"
  18. }
  19. }
  20. }
  21. }
  1. 删除请求:
  2. DELETE /goodsindex
  3. 返回:
  4. {
  5. "acknowledged" : true
  6. }

2,新增mapping映射

  1. //先创建索引
  2. PUT /xiaohui
  3. //创建mapping
  4. PUT /xiaohui/_mapping/goods //或 PUT /xiaohui/goods/_mapping
  5. {
  6. "properties": {
  7. "title":{
  8. "type":"text",
  9. "analyzer":"ik_max_word"
  10. },
  11. "subtilte":{
  12. "type":"text",
  13. "analyzer":"ik_max_word"
  14. },
  15. "images":{
  16. "type":"keyword",
  17. "index":"false"//表示不分词
  18. },
  19. "price":{
  20. "type":"float"
  21. }
  22. }
  23. }

一次性创建索引以及mapping映射:

  1. PUT /xiaohui2
  2. {
  3. "settings": {},
  4. "mappings": {
  5. "goods": {
  6. "properties": {
  7. "title": {
  8. "type": "text",
  9. "analyzer": "ik_max_word"
  10. },
  11. "subtilte": {
  12. "type": "text",
  13. "analyzer": "ik_max_word"
  14. },
  15. "images": {
  16. "type": "keyword",
  17. "index": "false"
  18. },
  19. "price": {
  20. "type": "float"
  21. }
  22. }
  23. }
  24. }

其中字段中的属性相关解释如下:

store:是否独立存储,默认数据都存储在_source下,个别独立出来的查询效率较高,默认false

3,文档操作

添加文档:

  1. 方式一:自动生成主键id:
  2. POST /xiaohui/goods
  3. {
  4. "title":"小米手机",
  5. "subtilte":"手机描述",
  6. "images":"http://www.shouji.com/sss.jpg",
  7. "price":2342
  8. }
  1. 方式二 指定id
  2. POST /xiaohui/goods/1001
  3. {
  4. "title":"小米手机2",
  5. "subtilte":"手机描述",
  6. "images":"http://www.shouji.com/sss.jpg",
  7. "price":2342
  8. }

文档查询:get /xiaohui/goods/1001

修改文档:

  1. PUT /xiaohui/goods/1001
  2. {
  3. "title":"红米手机2",
  4. "subtilte":"手机描述",
  5. "images":"http://www.shouji.com/sss.jpg",
  6. "price":2342
  7. }

删除文档:

  1. 删除1 根据id删除
  2. DELETE /xiaohui/goods/1001
  1. //删除2 根据查询条件删除
  2. POST /xiaohui/_delete_by_query
  3. {
  4. "query":{
  5. "match":{
  6. "title":"红米手机"
  7. }
  8. }
  9. }
  1. 删除3 全部删除:
  2. POST /xiaohui/_delete_by_query
  3. {
  4. "query":{
  5. "match_all":{}
  6. }
  7. }

批量新增(部分kibana版本可能不支持,不能进行格式化后执行)

  1. POST /xiaohui/goods/_bulk
  2. {"index":{}}{"title":"大米手机","images":"http://www.baidu.com/jjj.jpg","price":21222}
  3. {"index":{}}{"title":"小米手机","images":"http://www.baidu.com/jjj.jpg","price":21222}
  4. {"index":{}}{"title":"小米手机4A","images":"http://www.baidu.com/jjj.jpg","price":21222}

4,文档查询:

1,查询全部

  1. POST /xiaohui/_search
  2. {
  3. "query": {
  4. "match_all": {}
  5. }
  6. }

2,部分关键词查询

  1. POST /xiaohui/_search
  2. {
  3. "query": {
  4. "match": {
  5. "title": "小米电视4A"
  6. }
  7. }
  8. }

查询指定operator

operator:and 分词后都必须包含,or 包含其一就可以。

  1. POST /xiaohui/_search
  2. {
  3. "query": {
  4. "match": {
  5. "title":{
  6. "query":"小米手机4A",
  7. "operator":"and"
  8. }
  9. }
  10. }
  11. }

多字段查询:

  1. POST /xiaohui/_search
  2. {
  3. "query":{
  4. "multi_match": {
  5. "query": "小米",
  6. "fields": ["title","subtilte"]
  7. }
  8. }
  9. }

精确查询 term (可查询那些数字 日期 布尔值 以及未分词的字符串)

  1. POST /xiaohui/_search
  2. {
  3. "query":{
  4. "term": {
  5. "price": {
  6. "value": "5999"
  7. }
  8. }
  9. }
  10. }

同一字段 两个值精确查询

  1. POST /xiaohui/_search
  2. {
  3. "query":{
  4. "terms": {
  5. "price": ["5999","21222"]
  6. }
  7. }
  8. }

只返回需要的字段(左右等同)

POST /xiaohui/_search

{

  "_source": ["title","price"],

  "query":{

    "terms": {

      "price": ["5999"]

    }

  }

}

POST /xiaohui/_search

{

  "_source": {

    "includes":["title","price"]

  },

  "query":{

    "terms": {

      "price": ["5999"]

    }

  }

}

剔除不需要的字段

  1. POST /xiaohui/_search
  2. {
  3. "_source": {
  4. "excludes":["title"]
  5. },
  6. "query":{
  7. "terms": {
  8. "price": ["5999"]
  9. }
  10. }
  11. }

高级查询:

布尔组合bool

  1. POST /xiaohui/_search
  2. {
  3. "query":{
  4. "bool":{
  5. "must":{"match":{"title":"小米"}},
  6. "must_not":{"match":{"title":"4A"}},
  7. "should":{"match":{"subtitle":"华为"}}
  8. }
  9. }
  10. }

范围查询(range):gt 大于 gte 大于等于 lt小于 lte小于等于

  1. POST /xiaohui/_search
  2. {
  3. "query":{
  4. "range": {
  5. "price": {
  6. "gte": 1000,
  7. "lte": 6000
  8. }
  9. }
  10. }
  11. }

模糊查询(fuzzy):

  1. POST /xiaohui/_search
  2. {
  3. "query":{
  4. "fuzzy": {
  5. "title":{
  6. "value": "app22",
  7. "fuzziness":2 //容错个数
  8. }
  9. }
  10. }
  11. }

排序(soft)

  1. 单字段排序
  2. POST /xiaohui/_search
  3. {
  4. "query":{
  5. "match_all": {}
  6. },
  7. "sort": [
  8. {
  9. "price": {
  10. "order": "desc"
  11. }
  12. }
  13. ]
  14. }
  1. 多字段排序:
  2. POST /xiaohui/_search
  3. {
  4. "query":{
  5. "match":{
  6. "title":"小米"
  7. }
  8. },
  9. "sort": [
  10. {"_score": {"order": "desc"}},
  11. {"price": {"order": "desc"}}
  12. ]
  13. }

高亮展示(highlight)

  1. POST /xiaohui/_search
  2. {
  3. "query":{
  4. "match":{
  5. "title": "小米"
  6. }
  7. },
  8. "highlight": {
  9. "pre_tags": "<front color='red'>",
  10. "post_tags": "</front>",
  11. "fields": {"title": {}}
  12. }
  13. }

分页(from size)

  1. POST /xiaohui/_search
  2. {
  3. "query":{
  4. "match_all": {}
  5. },
  6. "from": 0,
  7. "size": 2
  8. }

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号