2015-01-15 58 views
0

复制我试图创建助推查询像documentation 显示出其但当我尝试提高查询,从文档

{ 
    "query": { 
    "match_all":{} 
    }, 
    "boosting": { 
    "positive": { 
     "term": { 
     "is_job_seeking": 1 
     } 
    }, 
    "negative": { 
     "term": { 
     "is_job_seeking": 0 
     } 
    } 
    }, 
    "negative_boost" : 0.2 
} 

它不工作我得到错误

error: SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; 
     shardFailures {[bP7jZnVHSRu83G30B0uSmw][idx_users_all_backup_dev][0]: 
     SearchParseException[[idx_users_all_backup_dev][0]: from[-1],size[-1]: 
     Parse Failure [Failed to parse source [ 
      { 
      "boosting": { 
       "positive": { 
       "term": { 
        "field1":"value1" 
       } 
       }, 
       "negative": { 
       "term": { 
        "field2":"value2" 
       } 
       }, 
       "negative_boost":0.2 
      } 
      } 
     ]]]; 
     nested: SearchParseException[[idx_users_all_backup_dev][0]: from[-1],size[-1]: 
     Parse Failure [No parser for element [boosting]]]; }{[bP7jZnVHSRu83G30B0uSmw][idx_users_all_backup_dev][1]: 
     SearchParseException[[idx_users_all_backup_dev][1]: from[-1],size[-1]: 
     Parse Failure [Failed to parse source [ 
      { 
      "boosting": { 
       "positive": { 
       "term": { 
        "field1":"value1" 
       } 
       }, 
       "negative": { 
       "term": { 
        "field2":"value2" 
       } 
       }, 
       "negative_boost":0.2 
      } 
      } 
     ]]]; 
     nested: SearchParseException[[idx_users_all_backup_dev][1]: from[-1],size[-1]: 
     Parse Failure [No parser for element [boosting]]]; }{[bP7jZnVHSRu83G30B0uSmw][idx_users_all_backup_dev][2]: 
     SearchParseException[[idx_users_all_backup_dev][2]: from[-1],size[-1]: 
     Parse Failure [Failed to parse source [ 
      { 
      "boosting": { 
       "positive": { 
       "term": { 
        "field1":"value1" 
       } 
       }, 
       "negative": { 
       "term": { 
        "field2":"value2" 
       } 
       }, 
       "negative_boost":0.2 
      } 
      } 
     ]]]; nested: SearchParseException[[idx_users_all_backup_dev][2]: from[-1],size[-1]: 
     Parse Failure [No parser for element [boosting]]]; }{[bP7jZnVHSRu83G30B0uSmw][idx_users_all_backup_dev][3]: 
     SearchParseException[[idx_users_all_backup_dev][3]: from[-1],size[-1]: 
     Parse Failure [Failed to parse source [ 
      { 
      "boosting": { 
       "positive": { 
       "term": { 
        "field1":"value1" 
       } 
       }, 
       "negative": { 
       "term": { 
        "field2":"value2" 
       } 
       }, 
       "negative_boost":0.2 
      } 
      } 
     ]]]; nested: SearchParseException[[idx_users_all_backup_dev][3]: from[-1],size[-1]: 
     Parse Failure [No parser for element [boosting]]]; }{[bP7jZnVHSRu83G30B0uSmw][idx_users_all_backup_dev][4]: 
     SearchParseException[[idx_users_all_backup_dev][4]: from[-1],size[-1]: 
     Parse Failure [Failed to parse source [ 
      { 
      "boosting": { 
       "positive": { 
       "term": { 
        "field1":"value1" 
       } 
       }, 
       "negative": { 
       "term": { 
        "field2":"value2" 
       } 
       }, 
       "negative_boost":0.2 
      } 
      } 
     ]]]; 
     nested: SearchParseException[[idx_users_all_backup_dev][4]: from[-1],size[-1]: 
     Parse Failure [No parser for element [boosting]]]; }] 
status: 400 

我还尝试添加explain: true,但它不会提供任何有关查询错误的额外信息。

编辑 我写这样的查询

{ 
    "sort": [ 
    { 
     "is_active": "asc" 
    } 
    ], 
    "fields": [ 
    "is_job_seeking", "is_active" 
    ], 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "bool": { 
      "must": { 
       "term": { 
       "is_job_seeking": 1 
       } 
      } 
      } 
     }, 
     { 
      "boosting": { 
      "positive": { 
       "term": { 
       "is_active": 1 
       } 
      }, 
      "negative": { 
       "term": { 
       "is_active": 0 
       } 
      }, 
      "negative_boost": 0.3 
      } 
     } 
     ] 
    } 
    } 
} 

与此查询给我1000倍的结果,但没有与is_active=0没有证件,当我删除boosting第一节纠正文档结果is_active=0

+1

按照安德烈的回答升压必须查询的一部分。在http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/not-quite-not.html#boosting-query –

回答

2

您的查询应该是这样的:

{ 
    "query": { 
    "boosting": { 
     "positive": { 
     "term": { 
      "is_job_seeking": 1 
     } 
     }, 
     "negative": { 
     "term": { 
      "is_job_seeking": 0 
     } 
     }, 
     "negative_boost": 0.2 
    } 
    } 
} 

随着bool

{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "term": { 
      "text": { 
       "value": "something" 
      } 
      } 
     }, 
     { 
      "boosting": { 
      "positive": { 
       "term": { 
       "is_job_seeking": 1 
       } 
      }, 
      "negative": { 
       "term": { 
       "is_job_seeking": 0 
       } 
      }, 
      "negative_boost": 0.2 
      } 
     } 
     ] 
    } 
    } 
} 
+0

有更好的文档示例,现在我可以在其中添加一些bool查询? ? –

+0

查看我的更新。你想做什么? –

+0

可以请你看看我的第一篇文章,我已经添加了一些代码 –