2017-07-21 9 views
0

私は以下の2つのクエリが同じ結果を得ることができることを知っています。しかし、Elasticsearchによって最後に解析されたクエリを見る方法があるので、それらが同じであることは確かに知ることができますか? (あるいは、彼らはおそらく1が、他にあまり時間がかかり、実際にはまったく同じではありません?)最後のクエリDSL Elasticsearchをどのように解析するのですか?

クエリ1:テスト用

GET /_search 
{ 
    "query": { 
    "term": { 
     "price": 20 
    } 
    } 
} 

答えて

1

とクエリを分析:

GET /_search 
{ 
    "query": { 
    "constant_score": { 
     "filter": { 
     "term": { 
      "price": 20 
     } 
     } 
    } 
    } 
} 

クエリ2 Slow Logを使用すると、クエリをログに記録し、フェーズをログファイルにフェッチできます。設定が非常に簡単です。インデックスごとに「低速クエリ」という意味を定義できます。 「サンプル」という名前のインデックスの

簡単な例(テスト目的のために、それが「0」に設定した時間にログインされます - あなたはあなた自身のしきい値を設定することができます):

最初のインデックスを閉じる:

curl -X POST http://127.0.0.1:9200/sample/_close 

curl -X PUT \ 
    'http://127.0.0.1:9200/sample/_settings?preserve_existing=true' \ 
    -d '{ 
    "index.indexing.slowlog.threshold.index.debug" : "0s", 
    "index.search.slowlog.threshold.fetch.debug" : "0s", 
    "index.search.slowlog.threshold.query.debug" : "0s" 
}' 

オープンインデックス:

curl -X POST http://127.0.0.1:9200/sample/_open 

は、次にスローログを設定します

あなたのポストで提供短いクエリを実行した後(私は5つの破片を持っていると、クエリがそれらのそれぞれに対して実行される):

[index.search.slowlog.query] [sample][1] took[594.1micros], ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}], 
[index.search.slowlog.query] [sample][3] took[649.4micros], ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}], 
[index.search.slowlog.query] [sample][4] took[575.6micros], ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}], 
[index.search.slowlog.query] [sample][2] took[1.2ms],  ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}], 
[index.search.slowlog.query] [sample][0] took[4.3ms],  ..., source[{"query":{"term":{"price":{"value":33,"boost":1.0}}}}], 
... 

をあなたはあなたのポストで提供長いクエリを実行した後:

[index.search.slowlog.query] [sample][1] took[13.2ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}], 
[index.search.slowlog.query] [sample][4] took[13.2ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}], 
[index.search.slowlog.query] [sample][3] took[14.7ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}], 
[index.search.slowlog.query] [sample][2] took[15.5ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}], 
[index.search.slowlog.query] [sample][0] took[15.5ms], ..., source[{"query":{"constant_score":{"filter":{"term":{"price":{"value":33,"boost":1.0}}},"boost":1.0}}}], 
... 

もちろん、これは1回の試行に過ぎませんが、詳細なテストや分析には非常に役立ちます。

関連する問題