Organizational Research By

Surprising Reserch Topic

Indexing and searching lists of data in elasticsearch


I'm trying to figure out how to use elasticsearch to index and search a bunch of lists. My current set-up is as follows:

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];

Is there a way to index my lists? Cause an item can belong to multiple lists and has no reference to what lists it belongs.

The ultimate goal is to find items with the word "great" in its title in itemList3.


asked Apr 15, 2015 in Elasticsearch-php by rajesh
0 votes
32 views



Related Hot Questions

1 Answer

0 votes

Here is an example that does what you want to do. At least from my understanding of your question. Index and query:

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" }
}}'

Result:

{
  "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" }]}
    } ]
  }
}
answered Apr 15, 2015 by rajesh

...