ES搜索(ElasticSearch)(四) Kibana

开启Kibana之旅

Kibana 是为 Elasticsearch设计的开源分析和可视化平台。你可以使用 Kibana 来搜索,查看存储在 Elasticsearch 索引中的数据并与之交互。你可以很容易实现高级的数据分析和可视化,以图表的形式展现出来。

直接下载对应平台的版本解压就可以,我的版本是Window kibana7.7.1,下装地址

config/kibana.yml 建议设置监听端口号、es地址、索引名
在这里插入图片描述
config/kibana.yml 建议配置成中文
在这里插入图片描述
点击kibana.bat启动
在这里插入图片描述
浏览器输入http://localhost:5601即可打开

打开控制台依次创建ES的index、settings、mapping
在这里插入图片描述

GET /test_v1/_settings

PUT /test_v1
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "analysis": {
      "analyzer": {
        "icu_analyzer": {
          "tokenizer": "icu_tokenizer"
        }
      }
    }
  }
}


GET /test_v1/_mapping

PUT /test_v1/_mapping
{
  "properties": {
    "itemId": {
      "type": "integer"
    },
    "categoryIds": {
      "type": "text",
      "analyzer": "whitespace",
      "fielddata": true
    },
	"tags": {
      "type": "text",
      "analyzer": "whitespace",
      "fielddata": true
    },
    "title": {
      "type": "text",
	  "analyzer": "icu_analyzer"
    },
    "summary": {
      "type": "text"
    },
    "marketPrice": {
      "type": "double"
    },
    "marketPriceTxt": {
      "type": "keyword"
    },
    "newFlag": {
      "type": "integer"
    },
    "attrsList": {
      "type": "nested",
      "properties": {
        "attrKey": {
          "type": "keyword"
        },
        "attrValue": {
          "type": "text",
          "analyzer": "whitespace"
        }
      }
    },
    "gmtCreate": {
      "type": "date",
      "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
    }
  }
}

POST /_aliases
{
    "actions": [
        { "add":    { "index": "test_v1", "alias": "test" }}
    ]
}

特别说明
1.title与summary都采用了分词,但是summary没有指定,实际搜索时分词结果时不一样的
2.attrsList采用的是nested,可以使用嵌套搜索(例如身高/颜色/尺码等等)
3.tags指定了空格分词,使用场景如标签/特性
4.添加别名时还可以设置其他属性如:“is_write_index”: true。别名可以和索引名有同样的功能,而且更强大。常见使用场景

/**
*由于Elasticsearch底层使用了lucene的原因,不支持对mapping的修改,可使用索引重建的方式,步骤如下
*/

//1,依照索引test_v1创建一份正确的索引test_v2
//2,使用reindex api将旧索引数据导入新索引,或者也可以采用把数据直接导入test_v2 
//索引重建后可使用reindex命令迁移数据,如将test_v1数据迁移至test_v2请求如下:
POST _reindex
{
  "source": {
    "index": "test_v1",
    "type": "item"
  },
  "dest": {
    "index": "test_v2",
    "type": "item"
  }
}
//3,将旧索引别名迁移到新索引请求   
POST /_aliases
{
    "actions" : [
        { "remove" : { "index" : "test_v1", "alias" : "test" } },
        { "add" : { "index" : "test_v2", "alias" : "test" } }
    ]
}
//4,删除旧索引,添加或迁移别名后删除旧索引:
DELETE /test_v1

5.其他语法

#清空数据
POST flmall_item_th_v1/_delete_by_query			
{
  "query": { 
    "match_all": {
    }
  }
}

#分词
GET /test/_analyze									
{
"analyzer": "icu_analyzer",
"text": "กระเป๋าสะพายสายกว้างแบบเข้าช"
}

#查询
GET test/_search
{
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "newFlag": {
              "value": 1,
              "boost": 1
            }
          }
        },
        {
          "match": {
            "categoryIds": {
              "query": "12",
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "auto_generate_synonyms_phrase_query": true,
              "boost": 1
            }
          }
        },
        {
          "nested": {
            "query": {
              "term": {
                "attrsList.attrKey": {
                  "value": "101",
                  "boost": 1
                }
              }
            },
            "path": "attrsList",
            "ignore_unmapped": false,
            "score_mode": "sum",
            "boost": 1
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "sid": {
              "value": "tigQqwdt",
              "boost": 1
            }
          }
        },
        {
          "nested": {
            "query": {
              "term": {
                "attrsList.attrValue": {
                  "value": "134",
                  "boost": 1
                }
              }
            },
            "path": "attrsList",
            "ignore_unmapped": false,
            "score_mode": "sum",
            "boost": 1
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "_source": {
    "includes": [
      "title",
      "sid",
      "itemId"
    ],
    "excludes": []
  },
  "sort": [
    {
      "_script": {
        "script": {
          "source": "doc['itemId'].value + params.randomSort",
          "lang": "painless",
          "params": {
            "randomSort": 100
          }
        },
        "type": "number",
        "order": "desc"
      }
    }
  ]
}

Kibana 可视化ElasticSearch数据展示分析 参考文档
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
禁用不必要的分词器可以提高Elasticsearch性能和查询效率。以下是一些常见的禁用不必要的分词器的方法: 1. 删除不必要的分词器插件:Elasticsearch默认启用了多个分词器插件,包括英语、法语、德语、西班牙语等多种语言的分词器。如果您的索引只包含一种语言的数据,可以删除其他语言的分词器插件以提高性能。 2. 禁用动态映射:Elasticsearch默认启用动态映射,它可以自动检测和添加新的字段索引中。但是,如果您的索引结构较为稳定,可以禁用动态映射来避免不必要的分词器的使用。 3. 禁用不必要的分析器:Elasticsearch默认启用多种分析器,包括标准分析器、简单分析器、语言分析器等。如果您的索引只需要使用一种分析器,可以禁用其他不必要的分析器。 4. 指定字段的分析器:在索引数据时,可以指定每个字段使用的分析器。如果某个字段不需要分析器,可以将其设置为“不分析”或使用“空”的分析器。 5. 禁用停用词过滤器:停用词过滤器用于从文本中删除常见单词,如“the”、“a”、“an”等。如果您的数据中没有太多常见单词,可以禁用停用词过滤器以提高性能。 总之,禁用不必要的分词器可以提高Elasticsearch的性能和查询效率。建议您根据自己的需求,选择合适的分词器和分析器,并禁用不必要的分词器,以提高Elasticsearch的性能。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值