倒排索引
倒排索引源于实际应用中需要根据属性的值来查找记录。这种索引表中的每一项都包括一个属性值和具有该属性值的各记录的地址。由于不是由记录来确定属性值,而是由属性值来确定记录的位置,因而称为倒排索引
。简单理解就是用各个索引来记录每个分词的位置。
查询分词
根据指定分词器进行解析。es 自带几个分词器:standard
、simple
、whitespace
curl -XPOST http://127.0.0.1:9200/_analyze?pretty -H'Content-Type:application/json' -d '{"analyzer":"ik","text":"2021-02-01 11:47:22.860 [admin-client-network-thread] WARN org.apache.kafka.clients.NetworkClient:671 - [NetworkClient clientId=admin-1051] Connection to node -1 could not be established. Broker may not be available."}'
插入doc
curl -XPUT http://127.0.0.1:9200/indexName/doc/uuid -H'Content-Type:application/json' -d {
"userName": "joe",
"pwd": "123456"
}
新建索引
curl -XPUT http://127.0.0.1:9200/indexName -H'Content-Type:application/json' -d
{
"mapping": "..."
}
删除索引
curl -XDELETE http://192.168.30.20:9200/department_process
查询:
相关度查询 multi_match,
全文检索 query_string,
分词后全文检索 matchQuery
使用 elasticdump 导入导出数据
https://www.npmjs.com/package/elasticdump
Installing
(local)
npm install elasticdump
./bin/elasticdump
(global)
npm install elasticdump -g
elasticdump
Backup templates to a file
elasticdump \
--input=http://192.168.1.14:9200/department_process \
--output=E://my_index.json \
--type=data
Import templates into ES
elasticdump \
--input=D://my_index.json \
--output=http://192.168.30.20:9200/department_process \
--type=data