索引和搜索elasticsearch中的数据列表

时间:2013-06-04 08:44:10

标签: 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”字样的项目。

1 个答案:

答案 0 :(得分: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" }]}
    } ]
  }
}