随笔分类 - ES-学习
摘要:课程大纲 1、重建索引 一个field的设置是不能被修改的,如果要修改一个Field,那么应该重新按照新的mapping,建立一个index,然后将数据批量查询出来,重新用bulk api写入index中 批量查询的时候,建议采用scroll api,并且采用多线程并发的方式来reindex数据,每
阅读全文
摘要:课程大纲 1、定制dynamic策略 true:遇到陌生字段,就进行dynamic mapping false:遇到陌生字段,就忽略 strict:遇到陌生字段,就报错 PUT /my_index { "mappings": { "my_type": { "dynamic": "strict", "
阅读全文
摘要:课程大纲 1、root object 就是某个type对应的mapping json,包括了properties,metadata(_id,_source,_type),settings(analyzer),其他settings(比如include_in_all) PUT /my_index { "
阅读全文
摘要:type,是一个index中用来区分类似的数据的,类似的数据,但是可能有不同的fields,而且有不同的属性来控制索引建立、分词器 field的value,在底层的lucene中建立索引的时候,全部是opaque bytes类型,不区分类型的 lucene是没有type的概念的,在document中
阅读全文
摘要:1、默认的分词器 standard standard tokenizer:以单词边界进行切分 standard token filter:什么都不做 lowercase token filter:将所有字母转换为小写 stop token filer(默认被禁用):移除停用词,比如a the it等
阅读全文
摘要:1、为什么我们要手动创建索引? 2、创建索引 创建索引的语法 PUT /my_index { "settings": { ... any settings ... }, "mappings": { "type_one": { ... any mappings ... }, "type_two": {
阅读全文
摘要:如果一次性要查出来比如10万条数据,那么性能会很差,此时一般会采取用scoll滚动查询,一批一批的查,直到所有数据都查询完处理完 使用scoll滚动搜索,可以先搜索一批数据,然后下次再搜索一批数据,以此类推,直到搜索出全部的数据来 scoll搜索会在第一次搜索的时候,保存一个当时的视图快照,之后只会
阅读全文
摘要:1、preference 决定了哪些shard会被用来执行搜索操作 _primary, _primary_first, _local, _only_node:xyz, _prefer_node:xyz, _shards:2,3 bouncing results问题,两个document排序,fiel
阅读全文
摘要:课程大纲 1、fetch phbase工作流程 (1)coordinate node构建完priority queue之后,就发送mget请求去所有shard上获取对应的document (2)各个shard将document返回给coordinate node (3)coordinate node
阅读全文
摘要:1、query phase (1)搜索请求发送到某一个coordinate node,构构建一个priority queue,长度以paging操作from和size为准,默认为10 (2)coordinate node将请求转发到所有shard,每个shard本地搜索,并构建一个本地的priori
阅读全文
摘要:搜索的时候,要依靠倒排索引;排序的时候,需要依靠正排索引,看到每个document的每个field,然后进行排序,所谓的正排索引,其实就是doc values 在建立索引的时候,一方面会建立倒排索引,以供搜索用;一方面会建立正排索引,也就是doc values,以供排序,聚合,过滤等操作使用 doc
阅读全文
摘要:课程大纲 1、算法介绍 relevance score算法,简单来说,就是计算出,一个索引中的文本,与搜索文本,他们之间的关联匹配程度 Elasticsearch使用的是 term frequency/inverse document frequency算法,简称为TF/IDF算法 Term fre
阅读全文
摘要:如果对一个string field进行排序,结果往往不准确,因为分词后是多个单词,再排序就不是我们想要的结果了 通常解决方案是,将一个string field建立两次索引,一个分词,用来进行搜索;一个不分词,用来进行排序 PUT /website { "mappings": { "article":
阅读全文
摘要:1、默认排序规则 默认情况下,是按照_score降序排序的 然而,某些情况下,可能没有有用的_score,比如说filter GET /_search { "query" : { "bool" : { "filter" : { "term" : { "author_id" : 1 } } } } }
阅读全文
摘要:GET /test_index/test_type/_validate/query?explain { "query": { "math": { "test_field": "test" } } } { "valid": false, "error": "org.elasticsearch.comm
阅读全文
摘要:课程大纲 GET /website/article/_search { "query": { "bool": { "must": [ { "match": { "title": "elasticsearch" } } ], "should": [ { "match": { "content": "e
阅读全文
摘要:课程大纲 1、match all GET /_search { "query": { "match_all": {} } } 2、match GET /_search { "query": { "match": { "title": "my elasticsearch article" }} } 3
阅读全文
摘要:课程大纲 1、filter与query示例 PUT /company/employee/2 { "address": { "country": "china", "province": "jiangsu", "city": "nanjing" }, "name": "tom", "age": 30,
阅读全文
摘要:课程大纲 1、一个例子让你明白什么是Query DSL GET /_search { "query": { "match_all": {} } } 2、Query DSL的基本语法 { QUERY_NAME: { ARGUMENT: VALUE, ARGUMENT: VALUE,... } } {
阅读全文
摘要:课程大纲 1、search api的基本语法 GET /search {} GET /index1,index2/type1,type2/search {} GET /_search { "from": 0, "size": 10 } 2、http协议中get是否可以带上request body H
阅读全文
浙公网安备 33010602011771号