2013-06-04 48 views
0

我想弄清楚如何使用elasticsearch来索引和搜索一堆列表。 我目前的设置如下:索引和搜索elasticsearch中的数据列表

var item1 = { "title" : "The Great Gatsby" }; 
var item2 = { "title" : "Ender's game" } 
var item3 = { "title" : "The name of the wind" } 

var itemList1 = [item1, item2]; 
var itemList2 = [item2, item3]; 
var itemList3 = [item3, item1]; 

有没有办法索引我的列表?导致项目可能属于多个列表,并且不参考它所属的列表。

最终目标是在itemList3的标题中找到单词“great”的项目。

回答

0

这是一个可以做你想做的事情的例子。至少从我对你的问题的理解来看。 索引和查询:

curl -XPUT localhost:9200/test/ 
curl -XPOST localhost:9200/test/testtype/1 -d '{"array" : [{ "title" : "The Great Gatsby" }, { "title" : "Enders game" }] }' 
curl -XPOST localhost:9200/test/testtype/2 -d '{"array" : [{ "title" : "Enders game" }, { "title" : "The name of the wind" }] }' 
curl -XPOST localhost:9200/test/testtype/3 -d '{"array" : [{ "title" : "The name of the wind" }, { "title" : "The Great Gatsby" }]}' 


curl -XPOST localhost:9200/test/testtype/_search -d '{ 
"query" : { 
    "term" : { "title" : "great" } 
}}' 

结果:

{ 
    "took" : 2, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 1, 
    "successful" : 1, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 2, 
    "max_score" : 0.5, 
    "hits" : [ { 
     "_index" : "test", 
     "_type" : "testtype", 
     "_id" : "1", 
     "_score" : 0.5, "_source" : {"array" : [{ "title" : "The Great Gatsby" }, { "title" : "Enders game" }] } 
    }, { 
     "_index" : "test", 
     "_type" : "testtype", 
     "_id" : "3", 
     "_score" : 0.5, "_source" : {"array" : [{ "title" : "The name of the wind" }, { "title" : "The Great Gatsby" }]} 
    } ] 
    } 
} 
+0

,如果一个项存在返回整个阵列。我试图过滤数组。 – Peeter