2014-02-11 4 views
1

Elasticsearch에서 쿼리를 최적화 할 수있는 방법이 있습니까? 아래 쿼리를 사용하고 있습니다. 그것의 평균은 15-20s이고 가끔은 약간 빠름 4-5s입니다.Elasticseach 쿼리 최적화

내 서버 구성 : -를 CentOS 6.3, 8 코어 16기가바이트 RAM

{ 
"fields": [ 
    "_id", 
    "aff_id", 
    "post_uri", 
    "blog_cat", 
    "cat_score", 
    "secondary_cat", 
    "secondary_cat_score", 
    "title", 
    "_score" 
], 
"min_score": 0.0134, 
"query": { 
    "bool": { 
    "must": [ 
     { 
      "query_string": { 
       "fields": [ 
       "title" 
       ], 
       "query": "Archery OR Athletics OR Badminton OR Basketball OR Beach Volleyball OR Boxing OR Canoe Slalom OR Canoe Sprint OR Cycling BMX OR Cycling Mountain Bike OR Cycling Road OR Cycling Track OR Diving OR Equestrian/Dressage OR Equestrian/Eventing OR Equestrian/Jumping OR Fencing OR Football OR Golf OR Gymnastics Artistic" 
      } 
     } 
    ], 
    "must_not": [], 
    "should": [] 
    } 
} 

나는

https://speakerdeck.com/elasticsearch/query-optimization-go-more-faster-better

시도 솔루션 변화 쿼리를 아래와 같이 Elasticsearch 쿼리 최적화에 관한 기사를 읽을 수 있지만하지 않습니다 어떤 차이.

{ 
    "fields": [ 
     "aff_id", 
     "post_uri", 
     "blog_cat", 
     "cat_score", 
     "secondary_cat", 
     "secondary_cat_score", 
     "title" 
    ], 
    "query": { 
     "filtered": { 
     "query": { 
      "bool": { 
       "must": [ 
        { 
        "term": { 
         "url.cat": "sports" 
        } 
        }, 
        { 
        "range": { 
         "main_cat.sports": { 
          "gte": ".15" 
         } 
        } 
        } 
       ] 
      } 
     }, 
     "filter": { 
      "query": { 
       "query_string": { 
        "fields": [ 
        "body", 
        "title" 
        ], 
        "query": "Archery OR Athletics OR Badminton OR Basketball OR Beach Volleyball OR Boxing OR Canoe Slalom OR Canoe Sprint OR Cycling BMX OR Cycling Mountain Bike OR Cycling Road OR Cycling Track OR Diving OR Equestrian/Dressage OR Equestrian/Eventing OR Equestrian/Jumping OR Fencing OR Football OR Golf OR Gymnastics Artistic" 
       } 
      } 
     } 
     } 
    }, 
    "from": 0, 
    "size": 1000 
} 

참고 : 나는 정의 분석기 정의하지 않은 기본 분석기를 사용하고.

+0

쿼리에서'fields' 섹션을 삭제 해 보셨습니까? 현재 색인에 몇 개의 레코드가 있습니까? 분석기 및 매핑 정의 란 무엇입니까? –

+0

예,'fields' 섹션을 삭제하려고했습니다. 내 인덱스에는 약 212,00,000 개의 레코드가 있습니다. – Roopendra

+0

'mappings'은 색인 생성 시간에 정의 된 매핑입니다. 게시 할 수 있습니까? BTW, 200M 레코드는 컴퓨터 구성 (16GB RAM)과 비교할 때 큰 숫자입니다. 색인의 크기를 확인하고 여기에 게시 할 수도 있습니다. 나는 보통 색인을 위해 64GB RAM을 빌려줍니다 (50GB 색인 데이터) –

답변

0

여기 쿼리의 최적화 버전입니다 : -

변경 : -

1) 쿼리에 filters를 사용 filter가 캐시됩니다.
2) query_string/query 필터는 기본적으로 캐시되지 않지만, _cache: true을 설정하여 필터를 켤 수 있습니다.

{ 
    "fields": [ 
     "aff_id", 
     "post_uri", 
     "blog_cat", 
     "cat_score", 
     "secondary_cat", 
     "secondary_cat_score", 
     "title" 
    ], 
    "query": { 
     "filtered": { 
     "filter": { 
      "bool": { 
       "must": [ 
        { 
        "term": { 
         "url.cat": "sports" 
        } 
        }, 
        { 
        "range": { 
         "main_cat.sports": { 
          "gte": ".15" 
         } 
        } 
        }, 
        { 
        "fquery": { 
         "query": { 
          "query_string": { 
           "fields": [ 
           "body", 
           "title" 
           ], 
           "query": "Archery OR Athletics OR Badminton OR Basketball OR Beach Volleyball OR Boxing OR Canoe Slalom OR Canoe Sprint OR Cycling BMX OR Cycling Mountain Bike OR Cycling Road OR Cycling Track OR Diving OR Equestrian/Dressage OR Equestrian/Eventing OR Equestrian/Jumping OR Fencing OR Football OR Golf OR Gymnastics Artisti" 
          } 
         }, 
         "_cache": true 
        } 
        } 
       ] 
      } 
     } 
     } 
    }, 
    "from": 0, 
    "size": 1000, 
    "sort": [ 
     { 
     "_uid": "desc" 
     } 
     ] 
}