2017-01-23 54 views
0
{"query": 
    {"filtered": 
    {"filter": 
     {"or": 
     [{"term":{"id_admin":255}},{"term":{"id_user":255}}] 
     }, 
    "query": 
     {"bool": 
     {"must": 
      [{"match":{"striped":"sentence"}}] 
     } 
     } 
    } 
    } 
} 

查询返回条目,其中id_adminid_user或为255和striped =句子。这个Elasticsearch查询可以被优化吗?

我们使用2.3.1版本。

此查询是否可以更优化?

回答

0

如果您在使用ES 2.3.1,写这个查询的正确方法如下:

{ 
    "query": { 
    "bool": { 
     "minimum_should_match": 1, 
     "should": [ 
     { 
      "term": { 
      "id_admin": 255 
      } 
     }, 
     { 
      "term": { 
      "id_user": 255 
      } 
     } 
     ], 
     "must": [ 
     { 
      "match": { 
      "striped": "sentence" 
      } 
     } 
     ] 
    } 
    } 
} 
+0

平均而言,在同样的环境下,我的查询比你快。 – GSG

+1

我只是说你正在使用的DSL语法[已被弃用](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/breaking_20_query_dsl_changes.html#_literal_filtered_literal_query_and_literal_query_literal_filter_deprecated),我的查询是您应该使用ES 2.x以上的版本。现在关于性能,我认为你已经负载测试两次查询几千次,以声称你的速度更快,或者你只是使用卷曲或头部或感觉进行一次性调用,并检查“花费”时间(哪不是很重要)? – Val

+0

对此有什么好运? – Val