我正在使用这种映射(嗯,这是一个更短的版本,以使问题更容易解决)的孩子-父母关系,其中item是parent和user_items是children。
curl -XPUT 'localhost:9200/myindex?pretty=true' -d '{
"mappings": {
"items": {
"dynamic": "strict",
"properties" : {
"title" : { "type": "string" },
"body" : { "type": "string" },
}},
"user_items": {
"dynamic": "strict",
"_parent": {"type": "items" },
"properties" : {
"user_id" : { "type": "integer" },
"source_id" : { "type": "integer" },
}}}}'以及我通常所做的查询类型:
curl -XGET 'localhost:9200/myindex/items/_search?pretty=true' -d '{
"query": {
"bool": {
"must": [
{
"query_string": {
"fields": ["title", "body"],
"query": "mercado"
}
},
{
"has_child": {
"type": "user_items",
"query": {
"term": {
"user_id": 655
}}}}]}}}'在这个查询中,它必须搜索字段title和body --给定user_id上的字符串mercado,在本例中是655。
这些查询中的第一个是veeeeeeeeeeeeeeeery,速度慢,最多需要15秒。以下是相当快的(<0.5秒)
我读到,第一个查询速度如此慢的原因是它得到了仙人掌,而其余的查询则是快速的,因为它与缓存的内容一起工作。
我读到我可以使用"loading" : "eager"来提升第一个查询。因此,我在一个名为myindex_new的新索引上创建了一个新的映射
{
"mappings": {
"items": {
"dynamic": "strict",
"properties" : {
"title" : { "type": "string" ,
"fielddata": {
"loading" : "eager"}},
"body" : { "type": "string",
"fielddata": {
"loading" : "eager"}},
}},
"user_items": {
"dynamic": "strict",
"_parent": {"type": "items" },
"properties" : {
"user_id" : { "type": "integer" },
"source_id" : { "type": "integer" },
}}}}'..。并按以下方式重新编制索引:
curl -XPOST 'localhost:9200/_reindex' -d '{
"source" : {
"index" : "myindex"
},
"dest" : {
"index" : "myindex_new"
}
}'问题是我没有得到更好的结果。如果我使用eager查询新索引,那么第一个查询仍然很慢。我也尝试过在子字段中添加eager,但是它仍然很慢。
我要做什么不同的事吗?我在重新索引上做错什么了吗?
提前感谢!
发布于 2016-11-10 02:40:42
Fielddata用于对这些特定字段进行排序和聚合。这将无助于您的特定查询,因为您不使用这些字段进行排序或内部聚合。我会尝试一种不同类型的急切加载,而不是在父字段的子字段上:"loading": "eager_global_ordinals"。更完整的示例这里。
父子关系使用全局序号来加速连接。全局序数有两个目的:降低将数字与字符串字段相关联和我前面提到的内存使用量。
Elasticserch正在使用父母和孩子之间的记忆连接来使这种关系发挥作用。对于这些连接,使用全局序号。他们需要建造和预装。使用"loading": "eager_global_ordinals",它应该预加载全局序数,并使搜索速度更快,因为这些联接已经在内存中预加载。
https://stackoverflow.com/questions/40129301
复制相似问题