2013-04-18 61 views
1

我正在尝试为Elastic Search编写一个查询,该查询将返回前20个最接近的匹配项。ES搜索查询调用并仅返回选定的字段

我想返回标题字段的前20个匹配项。

curl -X POST "localhost:9200/xxx/_search?pretty=true" -d ' 
{ 
"from" : 0, 
"size" : 20, 
"query" : { "term" : {"title" : "art"} }}' 

我在这里错过了什么?

更新:

我想只得到“标题”字段中返回,而不是整个对象。

+0

ES自动返回按分数odered结果。 – mbj

+0

查询看起来不错,默认排序是按分数。究竟是什么问题? – javanna

+0

啊,我刚刚看到我有一个缺失的大括号,但!问题是我试图让只有标题返回给我。不是整个对象。 – Mantas

回答

1

我做与领域PARAM搜索得到这个:

curl -X POST "localhost:9200/xxx/_search?pretty=true" -d ' 
{ 
"from" : 0, 
"size" : 20, 
"fields" : ["title"], 
"query" : { "term" : {"title" : "art"} }}'