码迷,mamicode.com
首页 > 其他好文 > 详细

分布式搜索elasticsearch 索引文档的检索 入门

时间:2014-10-14 20:48:29      阅读:127      评论:0      收藏:0      [点我收藏+]

标签: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": "音乐"
    }
  }
}

bubuko.com,布布扣

b、指定字段进行检索

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

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

bubuko.com,布布扣

c、多字段权重查询

在song、tag两个字段中搜索关键字“中国”,如果在song字段中出现权重是2,tag中是默认的1。通过结果可以看到歌曲名中含有中国是排在前面。

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

bubuko.com,布布扣

更多详细的查询语法可以参考:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-queries.html

分布式搜索elasticsearch 索引文档的检索 入门

标签:elasticsearch   分布式存储   分布式   搜索   

原文地址:http://blog.csdn.net/gdutliuyun827/article/details/40079077

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!