以下是我发送给ElasticSearch的查询:
http://localhost:9200/user-index/user/_search/?queryb%5Bname%5D=Richard
返回的JSON是:
{
"hits": [
{
"_index": "user-index",
"_type": "user",
"_id": "WgrvE-DzQJminNreBIsRNA",
"_score": 1.0,
"_source": {
"name": "Richard",
"db_id": "7"
}
},
{
"_index": "user-index",
"_type": "user",
"_id": "GwMOuYbUR8y48RrG4HgXdg",
"_score": 1.0,
"_source": {
"name": "John",
"db_id": "8"
}
},
{
"_index": "user-index",
"_type": "user",
"_id": "C-bgK3pNTNiX9Cz0x8EftA",
"_score": 1.0,
"_source": {
"name": "Harold",
"db_id": "2"
}
}
]
}
其中只有一个实际匹配。为什么要把它们全部送回去?
答案 0 :(得分:2)
Elasticsearch返回索引user-index中user类型的所有记录,因为它无法找到搜索查询。搜索查询应在the parameter "q"或a request body中指定为查询字符串。
尝试http://localhost:9200/user-index/user/_search?q=name%3ARichard