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的苦逼。

相關文章
相關標籤/搜索