ElasticSearch不返回所有结果

时间:2014-06-27 09:24:13

标签: rest search elasticsearch

我有这组数据

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 16,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100038",
      "_score" : 1.0, "_source" : {"id":"100038","patientPin":"2012010000000020","prescriptions":[],"diagnosis":["Amoebiasis"],"patientFirstName":"Scooby","patientLastName":"Doo","documentDate":"06/13/2014"}
    }, {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100007",
      "_score" : 1.0, "_source" : {"id":"100007","patientPin":"2012010000000016","prescriptions":["METHISOPRINOL ISOPRINOSINE"],"diagnosis":["Alcohol Intoxication"],"patientFirstName":"Johnny","patientLastName":"Bravo","documentDate":"06/10/2014"}
    }, {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100015",
      "_score" : 1.0, "_source" : {"id":"100015","patientPin":"2012010000000010","prescriptions":[],"diagnosis":["Amoebiasis"],"patientFirstName":"Tweety","patientLastName":"Bird","documentDate":"06/10/2014"}
    }, {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100027",
      "_score" : 1.0, "_source" : {"id":"100027","patientPin":"2012010000000014","prescriptions":[],"diagnosis":["Food Poisoning"],"patientFirstName":"Marvin","patientLastName":"Martian","documentDate":"06/11/2014"}
    }, {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100046",
      "_score" : 1.0, "_source" : {"id":"100046","patientPin":"2012010000000027","prescriptions":[],"diagnosis":["Amoebiasis"],"patientFirstName":"Yabba","patientLastName":"Doo","documentDate":"06/13/2014"}
    }, {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100058",
      "_score" : 1.0, "_source" : {"id":"100058","patientPin":"2012010000000003","prescriptions":[],"diagnosis":["Amoebiasis"],"patientFirstName":"Elmer","patientLastName":"Fudd","documentDate":"06/13/2014"}
    }, {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100042",
      "_score" : 1.0, "_source" : {"id":"100042","patientPin":"2012010000000021","prescriptions":[],"diagnosis":["Amoebiasis"],"patientFirstName":"Scrappy","patientLastName":"Doo","documentDate":"06/13/2014"}
    }, {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100054",
      "_score" : 1.0, "_source" : {"id":"100054","patientPin":"2012010000000026","prescriptions":[],"diagnosis":["Amoebiasis"],"patientFirstName":"Scooby","patientLastName":"Dum","documentDate":"06/13/2014"}
    }, {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100066",
      "_score" : 1.0, "_source" : {"id":"100066","patientPin":"2012010000000015","prescriptions":[],"diagnosis":["Amoebiasis"],"patientFirstName":"Hippety","patientLastName":"Hopper","documentDate":"06/13/2014"}
    }, {
      "_index" : "tenant1",
      "_type" : "consultation",
      "_id" : "100050",
      "_score" : 1.0, "_source" : {"id":"100050","patientPin":"2012010000000002","prescriptions":[],"diagnosis":["Amoebiasis"],"patientFirstName":"Daffy","patientLastName":"Duck","documentDate":"06/13/2014"}
    } ]
  }
}

然而,当我通过Google Chromes'使用此查询的Rest控制台

{
    "query" : {
        "match" : {
            "patientFirstName" : "Scooby"
        }
    }
}

它返回所有结果,这是我用来搜索的网址

http://localhost:9200/tenant1/consultation/_search

我甚至也做过

http://localhost:9200/tenant1/consultation/_search?patientLastName:Doo

它仍会返回所有结果。它应该只返回一个结果

2 个答案:

答案 0 :(得分:2)

将您的查询更改为此。(添加_search?q =)

http://localhost:9200/tenant1/consultation/_search?q=patientLastName:Doo

答案 1 :(得分:0)

尝试一个bool查询,这将确保它具有以下结果返回它 -

{
    "query": {
        "bool": {
            "must": {
                "term": {
                    "patientFirstName": "Scooby"
                }
            }
        }
    }
}

更多信息here.