不为失败找理由,要为成功找方法。

本机安装es后dsl查询不起作用

Elasticsearch | 作者 csbag | 发布于2015年12月29日 | 阅读数:4465

今天开始学习es,现在本地已配置es服务,根据网上教程进行测试,使用DSL查询方式出错,请大神指点

1、使用普通字符串查询

curl -GET 'http://localhost:9200/megacorp/employee/_search?q=_id:1&pretty'
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "megacorp",
      "_type" : "employee",
      "_id" : "1",
      "_score" : 1.0,
      "_source":{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        25,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}
    } ]
  }
}

2、使用DSL语句查询
curl -GET 'http://localhost:9200/megacorp/employee/_search?pretty' -d "{"query":{"match":{"_id":"1"}}}"
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "megacorp",
      "_type" : "employee",
      "_id" : "2",
      "_score" : 1.0,
      "_source":{
    "first_name" :  "Jane",
    "last_name" :   "Smith",
    "age" :         32,
    "about" :       "I like to collect rock albums",
    "interests":  [ "music" ]
}
    }, {
      "_index" : "megacorp",
      "_type" : "employee",
      "_id" : "1",
      "_score" : 1.0,
      "_source":{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        25,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}
    }, {
      "_index" : "megacorp",
      "_type" : "employee",
      "_id" : "3",
      "_score" : 1.0,
      "_source":{
    "first_name" :  "Douglas",
    "last_name" :   "Fir",
    "age" :         35,
    "about":        "I like to build cabinets",
    "interests":  [ "forestry" ]
}
    } ]
  }
}
为什么DSL方式会出现查询不准确问题!!
 
已邀请:

medcl - 今晚打老虎。

赞同来自: csbag

GET->POST

要回复问题请先登录注册