【发布时间】:2014-10-09 06:55:43
【问题描述】:
我的数据库中有以下类型的 json:
{
"_id" : "519817e508a16b447c00020e", "keyword" : "Just an example query",
"results" :
{
"1" : {"base_domain" : "example1.com", "href" : "http://www.example1.com/"},
"2" : { "base_domain" : "example2.com", "href" : "http://www.example2.com/"},
"3" : { "base_domain" : "example3.com", "href" : "http://www.example3.com/"},
"4" : { "base_domain" : "example4.com", "href" : "http://www.example4.com/"},
"5" : { "base_domain" : "example5.com", "href" : "http://www.example5.com/"},
"6" : { "base_domain" : "example6.com", "href" : "http://www.example6.com/"},
"7" : { "base_domain" : "example7.com", "href" : "http://www.example7.com/"},
"8" : { "base_domain" : "example8.com", "href" : "http://www.example8.com/"},
"9" : { "base_domain" : "example9.com", "href" : "http://www.example9.com/"},
"10" : { "base_domain" : "example10.com", "href" : "http://www.example10.com/"}
}
}
我的目标是获得以下查询的结果:
> db.ranking.find({ $text: { $search: "http://www.example9.com"}})
当我在所有文本字段上创建索引时它会起作用
> db.ranking.ensureIndex({ "$**": "text" }))
但不是当我只在“结果”字段上创建索引时:
> db.ranking.ensureIndex( {"results" : "text"} )
为什么?
【问题讨论】: