【问题标题】:ElasticSearch error: [function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]ElasticSearch 错误:[function_score] 格式错误的查询,应为 [END_OBJECT] 但找到 [FIELD_NAME]
【发布时间】:2017-12-01 00:27:07
【问题描述】:

以下 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]

布尔查询本身可以完美运行,但是一旦我使用 function_score,它就会停止工作。我试图遵循这个例子:https://www.elastic.co/guide/en/elasticsearch/guide/master/boosting-by-popularity.html

任何关于我做错了什么的想法将不胜感激!

【问题讨论】:

    标签: python elasticsearch


    【解决方案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
    }
    

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 1970-01-01
      • 2018-01-30
      • 2018-02-10
      • 2018-04-25
      • 2021-04-22
      • 2020-02-26
      • 1970-01-01
      • 2022-01-14
      相关资源
      最近更新 更多