具有聚合的同义词分析器给出“无法解析名称为 [匹配] 的 BaseAggregationBuilder:找不到解析器”错误

Posted

技术标签:

【中文标题】具有聚合的同义词分析器给出“无法解析名称为 [匹配] 的 BaseAggregationBuilder:找不到解析器”错误【英文标题】:Synonym analyzer with aggregation gives "unable to parse BaseAggregationBuilder with name [match]: parser not found" error 【发布时间】:2021-07-23 05:04:30 【问题描述】:

在我将同义词分析器添加到映射之前,我有一个 Elastic Search 项目,我的聚合和过滤器工作正常。 当前工作映射:

"settings": 
        "analysis": 
            "normalizer": 
                "lowercase": 
                "type": "custom",
                "filter": ["lowercase"]
                
            
        
    ,
 "mappings": 
        "doc": 
            "dynamic": "false",
            "properties": 
              "primarytrades": 
                    "type": "nested",
                    "properties" :
                        "name": 
                            "type": "text",
                            "fields": 
                                "keyword": 
                                    "type": "keyword",
                                    "ignore_above": 256,
                                    "normalizer": "lowercase"
                                
                            
                        
                     
                   
                
             
          

#这是带有预期分桶值的请求和响应:

请求: "aggs":"filter_trades":"aggs":"nested_trades":"aggs":"autocomplete_trades":"terms":"field":"primarytrades.name.keyword","include ":".*p.*l.*u.*m.b.","size":10,"nested":"path":"primarytrades" ,"filter":"nested":"path":"primarytrades","query":"bool":"should":["match":"primarytrades.name":"fuzziness ":2,"query":"plumb","match_phrase_prefix":"primarytrades.name":"query":"plumb"],"query": "bool":"filter":["nested":"path":"primarytrades","query":"bool":"should":["match":"primarytrades.name ":"fuzziness":2,"query":"plumb","match_phrase_prefix":"primarytrades.name":"query":"plumb"]] ,"大小":0

回应: "took":1,"timed_out":false,"_shards":"total":5,"successful":5,"skipped":0,"failed":0,"hits":"total ":7216,"max_score":0.0,"hits":[],"aggregations":"filter#filter_trades":"doc_count":7216,"nested#ne​​sted_trades":"doc_count":48496," sterms#autocomplete_trades":"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":["key":"plumbing","doc_count":7192,"key":"plumbing parts"," doc_count":179]

为了添加同义词搜索功能,我使用同义词分析器更改了映射,如下所示:

 "settings": 
      "analysis": 
        "normalizer": 
          "lowercase": 
            "type": "custom",
            "filter": [ "lowercase" ]
          
        ,
        "analyzer": 
          "synonym_analyzer": 
            "type": "custom",
            "tokenizer": "standard",
            "filter": [ "lowercase", "my_synonyms" ]
          
        ,
        "filter": 
          "my_synonyms": 
            "type": "synonym",
            "synonyms": [ "piping, sink, plumbing" ],
            "updateable": true
          
        
      
    ,
    "mappings": 
        "doc": 
            "dynamic": "false",
            "properties": 
                "primarytrades": 
                    "type": "nested",
                    "properties" :
                      "name": 
                        "type": "text",
                        "fields": 
                          "keyword": 
                            "type": "keyword",
                            "ignore_above": 256
                          ,
                          "analyzed": 
                            "type": "text",
                            "analyzer": "standard",
                            "search_analyzer": "synonym_analyzer"
                          
                        
                      
                    
              
        
    

此外,我将查询更改为使用 search_analyzer,如下所示:

"aggs":"filter_trades":"aggs":"nested_trades":"aggs":"autocomplete_trades":"match":"field":"primarytrades.name.analyzed" ,"include":".*p.*l.*u.*m.b.","size":10,"nested":"path":"primarytrades ","filter":"nested":"path":"primarytrades","query":"bool":"should":["match":"primarytrades.name": "fuzziness":2,"query":"plumb","search_analyzer":"synonym_analyzer","match_phrase_prefix":"primarytrades.name":"query":"plumb","search_analyzer" :"synonym_analyzer"],"query":"bool":"filter":["nested":"path":"primarytrades","query":" bool":"should":["match":"primarytrades.name":"fuzziness":2,"query":"plumb","search_analyzer":"synonym_analyzer","match_phrase_prefix ":"primarytrades.name":"query":"plumb","search_analyzer":"synonym_analyzer"]]

我收到此错误: "type": "named_object_not_found_exception", “原因”:“[8:24] 无法解析名称为 [匹配] 的 BaseAggregationBuilder:找不到解析器”

有人可以帮我更正查询吗?

提前致谢!

【问题讨论】:

对于聚合我在 "significant_text" 上尝试了 "field": "primarytrades.name.analyzed" 并且错误消失了,但我的存储桶没有任何值。同样,我在“terms”上使用了“field”:“primarytrades.name.keyword”,但我没有得到任何桶的值。如何根据同义词分析器和过滤器获取存储桶值? 【参考方案1】:

在您的match 查询中,您需要指定analyzer 而不是search_analyzersearch_analyzer 只是映射部分的有效关键字。

              
                "match": 
                  "primarytrades.name": 
                    "fuzziness": 2,
                    "query": "plumb",
                    "analyzer": "synonym_analyzer"      <--- change this
                  
                
              ,

【讨论】:

感谢您的回复。很有帮助 酷,如果有帮助,请随时接受 ;-)

以上是关于具有聚合的同义词分析器给出“无法解析名称为 [匹配] 的 BaseAggregationBuilder:找不到解析器”错误的主要内容,如果未能解决你的问题,请参考以下文章

MongoDB展开聚合查询给出意想不到的结果

如何在 Python NLTK 中提取 WordNet 同义词集的偏移量并给出同义词集?

如何在一个 groupby 列上执行聚合选项,给出两列输出

sql server 模糊查询和聚合函数

sql server 模糊查询和聚合函数

情感分析:基于循环神经网络