ElasticSearch错误:[function_score]格式错误的查询,预期[END_OBJECT]但找到[FIELD_NAME]

时间:2017-06-27 20:04:27

标签: python elasticsearch

以下JSON结构在执行查询时出错:

{                                                                                                                                                                                                                                                                                        
    "query": {                                                                                                                                                                                                                                                                           
        "function_score": {                                                                                                                                                                                                                                                              
            "query": {                                                                                                                                                                                                                                                                   
                "bool": {                                                                                                                                                                                                                                                                
                    "should": [                                                                                                                                                                                                                                                          
                        {                                                                                                                                                                                                                                                                
                            "multi_match": {                                                                                                                                                                                                                                             
                                "query": "BRCA1",                                                                                                                                                                                                                                        
                                "fuzziness": "AUTO",                                                                                                                                                                                                                                     
                                "fields": [                                                                                                                                                                                                                                              
                                    "Long_Name",                                                                                                                                                                                                                                         
                                    "Short_Name",                                                                                                                                                                                                                                        
                                    "Uniprot_ID^10",                                                                                                                                                                                                                                     
                                    "Genes^2",                                                                                                                                                                                                                                           
                                    "Diseases^2",                                                                                                                                                                                                                                        
                                    "Function",                                                                                                                                                                                                                                          
                                    "Domains"                                                                                                                                                                                                                                            
                                ]                                                                                                                                                                                                                                                        
                            }                                                                                                                                                                                                                                                            
                        },                                                                                                                                                                                                                                                               
                        {                                                                                                                                                                                                                                                                
                            "term": {                                                                                                                                                                                                                                                    
                                "Is_Reviewed": true                                                                                                                                                                                                                                      
                            }                                                                                                                                                                                                                                                            
                        },                                                                                                                                                                                                                                                               
                        {                                                                                                                                                                                                                                                                
                            "term": {                                                                                                                                                                                                                                                    
                                "Has_Function": true                                                                                                                                                                                                                                     
                            }                                                                                                                                                                                                                                                            
                        }                                                                                                                                                                                                                                                                
                    ]                                                                                                                                                                                                                                                                    
                }                                                                                                                                                                                                                                                                        
            }                                                                                                                                                                                                                                                                            
        },                                                                                                                                                                                                                                                                               
        "field_value_factor": {                                                                                                                                                                                                                                                          
            "field": "Number_Of_Structures"                                                                                                                                                                                                                                              
        }                                                                                                                                                                                                                                                                                
    },                                                                                                                                                                                                                                                                                   
    "size": 100                                                                                                                                                                                                                                                                          
}  

错误是:

[function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

bool查询本身可以很好地工作,但是一旦我使用function_score,它就会停止工作。我试图效仿这个例子:https://www.elastic.co/guide/en/elasticsearch/guide/master/boosting-by-popularity.html

我非常感谢任何关于我做错事的想法!

1 个答案:

答案 0 :(得分:1)

您必须在field_value_factor

中将function_score提高一级
{
    "query": {
        "function_score": {
            "query": {
                "bool": {
                    "should": [
                        {
                            "multi_match": {
                                "query": "BRCA1",
                                "fuzziness": "AUTO",
                                "fields": [
                                    "Long_Name",
                                    "Short_Name",
                                    "Uniprot_ID^10",
                                    "Genes^2",
                                    "Diseases^2",
                                    "Function",
                                    "Domains"
                                ]
                            }
                        },
                        {
                            "term": {
                                "Is_Reviewed": true
                            }
                        },
                        {
                            "term": {
                                "Has_Function": true
                            }
                        }
                    ]
                }
            },
            "field_value_factor": {
                "field": "Number_Of_Structures"
            }
        }
    },
    "size": 100
}