以下是我的弹性搜索 - 1.5查询:
{
"_source":["_id","spotlight"],
"query":{
"filtered":{
"filter":{
"and":[
{"term":{"gender":"female"}},
{"range":{"lastlogindate":{"gte":"2016-10-19 12:39:57"}}}
]
}
}
},
"filter":{
"and":[
{"term":{"maritalstatus":"1"}}
]
},
"sort":[{"member2_dummy7":{"order":"desc"}}],
"size":"600",
"aggs": {
"maritalstatus": {
"filter": {},
"aggs" : {
"filtered_maritalstatus": {"terms":{"field":"maritalstatus","size":5000}}
}
},
"relationship": {
"filter": {"term":{"maritalstatus":"1"}},
"aggs" : {
"filtered_relationship": {"terms":{"field":"relationship","size":5000}}
}
}
}
}
我在弹性5.1中转换了相同的查询,如下所示:
{
"_source":["_id","spotlight"],
"query": {
"bool": {
"filter": [
{"term":{"gender":"female"}},
{"range":{"lastlogindate":{"gte":"2016-10-19 12:39:57"}}}
]
}
},
"post_filter": {"term":{"maritalstatus":"1"}},
"sort":[{"member2_dummy7":{"order":"desc"}}],
"size":"600",
"aggs": {
"maritalstatus": {
"filter": {},
"aggs" : {
"filtered_maritalstatus": {"terms":{"field":"maritalstatus","size":5000}}
}
},
"relationship": {
"filter": {"term":{"maritalstatus":"1"}},
"aggs" : {
"filtered_relationship": {"terms":{"field":"relationship","size":5000}}
}
}
}
}
我在相同配置的两个不同AWS实例上运行了两个查询,最后,我发现弹性搜索5.1查询正在执行弹性搜索1.5查询的两倍时间。
有人可以告诉我为什么弹性搜索5.1查询运行速度比弹性搜索1.5 ????是否还需要进行查询优化才能使其快速运行?
为了更好的测试,我从查询中删除了所有内容并保留了一个条件并使用jmeter进行了测试。
以下是我的弹性搜索1.5查询:
{
"_source":["_id","spotlight"],
"query":{
"filtered":{
"filter":{
"and":[
{"term":{"gender":"female"}}
]
}
}
}
}
以下是我的弹性搜索5.1查询:
{
"_source":["_id","spotlight"],
"query": {
"bool": {
"filter": [
{"term":{"gender":"female"}}
]
}
}
}
以下是弹性搜索5.1中的映射:
{
"settings": {
"analysis": {
"analyzer": {
"lowercase_analyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": ["lowercase"]
}
}
},
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"profiles": {
"properties": {
"gender": {
"type": "text",
"analyzer": "lowercase_analyzer"
}
}
}
}
}
以下是弹性搜索1.5中的映射:
{
"settings": {
"analysis": {
"analyzer": {
"string_lowercase": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
},
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"profiles": {
"properties": {
"gender": {
"type": "string",
"analyzer": "string_lowercase"
}
}
}
}
}
Elastic-search 1.5查询耗时17 ms,Elastic-search 5.1查询耗时23 ms。这是平均时间,这种差异在所有领域都是一致的。我不明白为什么它运行缓慢。弹性搜索5.1是否比弹性搜索1.5 ???