分布式搜索elasticsearch 文献检索索引 入门

1、首先,例如,下面的数据被提交给ES该指数

{"number":32768,"singer":"杨坤","size":"5109132","song":"今夜二十岁","tag":"中国好声音","timelen":319}
{"number":32769,"singer":"汪峰","size":"6001697","song":"我爱你中国","tag":"中国好声音","timelen":375}
{"number":32780,"singer":"汪峰","size":"4070469","song":"我如此爱你","tag":"中国好声音","timelen":254}
{"number":32796,"singer":"大小姐","size":"3046005","song":"登大人","tag":"儿歌","timelen":190}
{"number":32896,"singer":"Bandari","size":"3869593","song":"The Golden Land","tag":"胎教音乐","timelen":241}
{"number":32977,"singer":"Bandari","size":"3477514","song":"Childhood Memory","tag":"欧美","timelen":217}

2、ElasticSearch's query DSL

搜索的RESTful接口是_search

URL形式:http://ip:port/index/type/_search

query查询语句通过POST的方式发送到ES。

a、主要的全文检索

查找索引库中包括"音乐"的记录

{
  "query": {
    "query_string": {
      "query": "音乐"
    }
  }
}

分布式搜索elasticsearch 文献检索索引 入门_第1张图片

b、指定字段进行检索

查找song字段中含有中国的记录

{
  "query": {
    "query_string": {
      "query": "中国",
      "fields": [
        "song"
      ]
    }
  }
}

分布式搜索elasticsearch 文献检索索引 入门_第2张图片

c、多字段权重查询

在song、tag两个字段中搜索keyword“中国”,假设在song字段中出现权重是2。tag中是默认的1。

通过结果能够看到歌曲名中含有中国是排在前面。

{
  "query": {
    "multi_match": {
      "query": "中国",
      "fields": [
        "song^2",
        "tag"
      ]
    }
  }
}

分布式搜索elasticsearch 文献检索索引 入门_第3张图片

很多其它具体的查询语法能够參考:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-queries.html

版权声明:本文博客原创文章,博客,未经同意,不得转载。

你可能感兴趣的:(elasticsearch)