1

我试图弄清楚如何使用 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”一词的项目。

4

1 回答 1

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" }]}
    } ]
  }
}
于 2013-06-04T10:13:56.220 回答