elasticsearch-搜索、高亮

https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.htmlhtml

https://my.oschina.net/u/856051/blog/1486979json

1,轻量搜索缓存

查询tweet字段包含elasticsearch字符的文档app

GET /_all/tweet/_search?q=tweet:elasticsearch

多查询字段查询GET /_all/tweet/_search?+name:john +tweet:marycurl

+ 前缀表示必须与查询条件匹配。相似地, - 前缀表示必定不与查询条件匹配。没有 + 或者 - 的全部其余条件都是可选的——匹配的越多,文档就越相关。elasticsearch

全文检索:_allide

2,映射ui

es对输入的每一个字符类型都须要进行映射this

  • 字符串: string
  • 整数 : byteshortintegerlong
  • 浮点数: floatdouble
  • 布尔型: boolean
  • 日期: date

es也能够自定义数据类型。url

当你索引一个包含新域的文档--以前不曾出现-- Elasticsearch 会使用 动态映射 ,经过JSON中基本数据类型,尝试猜想域类型,使用以下规则:

JSON type

域 type

布尔型: true 或者 false

boolean

整数: 123

long

浮点数: 123.45

double

字符串,有效日期: 2014-09-15

date

字符串: foo bar

string

获取es数据类型

http://localhost:9200/index/_mapping/type?pretty

3,复杂搜索

   查询表达式(Query DSL),以及复合(Compound) 语句,eg

GET /_search
{
    "query": {
        "match": {
            "tweet": "elasticsearch"
        }
    }
}

 

es查询分两种机制:过滤和查询

过滤,符合条件,选出,不符合条件,删除。且过滤会被缓存。

查询:当使用于 查询状况 时,查询就变成了一个“评分”的查询。和不评分的查询相似,也要去判断这个文档是否匹配,同时它还须要判断这个文档匹配的有 _多好_(匹配程度如何)。最后变成score在结果中显示。

 

3,高亮功能

 

4,自定义数据类型;

   define:对时间格式进行自定义:

curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "date": {
          "type":   "date",
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        },
        "name" : {
          "type" :   "string"
        },
        "user_id" : {
          "type" :   "long"
        }
      }
    }
  }
}
'

put:

curl -XPUT 'localhost:9200/my_index/my_type/123?pretty' -H 'Content-Type: application/json' -d'
{
  "user_id": 1,
  "name":  "Just trying this out...",
  "date":  "2014-01-01 08:08:08"
}

show:

技术组老大搞es date类型:

由于这个T搞得我很是狼狈,明明是这个leader的技术问题,能够自定义标准的yyyy-MM-dd HH:mm:ss,却说只能用es自带的带T格式,带Z格式的时间,搞得我如今这么惨。哎,算了,男人的胸怀是被委屈撑大的。真tm的苦逼。

相关文章
相关标签/搜索