【问题标题】:Elasticsearch's Common Terms Query, use and compatibility with query typesElasticsearch 的常用术语查询、使用和与查询类型的兼容性
【发布时间】:2014-02-06 23:21:24
【问题描述】:

我目前正在调查常用术语查询的使用,并且由于文档有点缺乏(要么就是我没有找到关于这些问题的任何文档),我不完全确定某些操作是否与 common 不兼容术语查询,或者我做错了。

我目前在 Ubuntu 12.04 64 位中使用 Elasticsearch 版本 0.90.5。

这是我观察到的:

  • 查询类型 match 和 match_phrase 似乎与 high_freq_operator、low_freq_operator 和 minimum_should_match 选项的使用不兼容。 (例如[match] query does not support [high_freq_operator] 和类似的)

  • and、or、and not(复合表达式)在其组成表达式指定使用常用术语时,似乎会产生损坏的底层表达式。 (例如[_na] filter malformed, must start with start_object

  • span_term 查询似乎与常用术语查询不兼容。 (例如[span_term] query does not support [common]

我的查询如下所示:

这个解析例如...

{   "query": {                                                                                                                                                                                                                              
        "match_phrase": {                                                                                                                                                                                                                   
            "subject": {                                                                                                                                                                                                                    
                "common": {                                                                                                                                                                                                                 
                    "body": {                                                                                                                                                                                                               
                        "cutoff_frequency": 0.001,                                                                                                                                                                                          
                        "query": "something not important"                                                                                                                                                                                  
                    }                                                                                                                                                                                                                       
                }                                                                                                                                                                                                                           
            }                                                                                                                                                                                                                               
        }                                                                                                                                                                                                                                   
    }                                                                                                                                                                                                                                       
} 

这个解析失败,引用“[match] query does not support [high_freq_operator]”:

{"query": {                                                                                                                                                                                                                              
        "match_phrase": {                                                                                                                                                                                                                   
            "subject": {                                                                                                                                                                                                                    
                "common": {                                                                                                                                                                                                                 
                    "body": {                                                                                                                                                                                                               
                        "cutoff_frequency": 0.001,
                        "high_freq_operator": "or",                                                                                                                                                                                          
                        "query": "something not important"                                                                                                                                                                                  
                    }                                                                                                                                                                                                                       
                }                                                                                                                                                                                                                           
            }                                                                                                                                                                                                                               
        }                                                                                                                                                                                                                                   
    }                                                                                                                                                                                                                                       
} 

这个解析失败,引用“filter malformed, must start with start_object”:

{                                                                                                                                                                                                                                           
    "filter": {                                                                                                                                                                                                                             
        "or": [                                                                                                                                                                                                                             
            {                                                                                                                                                                                                                               
                "query": {                                                                                                                                                                                                                  
                    "match": {                                                                                                                                                                                                              
                        "subject": {                                                                                                                                                                                                  
                            "common": {                                                                                                                                                                                                     
                                "body": {                                                                                                                                                                                                   
                                    "cutoff_frequency": 0.001,                                                                                                                                                                              
                                    "query": "PLEASE READ: something not important"                                                                                                                                                         
                                }                                                                                                                                                                                                           
                            }                                                                                                                                                                                                               
                        }                                                                                                                                                                                                                   
                    }                                                                                                                                                                                                                       
                }                                                                                                                                                                                                                           
            },                                                                                                                                                                                                                              
            {                                                                                                                                                                                                                               
                "query": {                                                                                                                                                                                                                  
                    "range": {                                                                                                                                                                                                              
                        "date": {                                                                                                                                                                                                           
                            "to": "2009-12-31T23:59:59Z"                                                                                                                                                                                    
                        }                                                                                                                                                                                                                   
                    }                                                                                                                                                                                                                       
                }                                                                                                                                                                                                                           
            }                                                                                                                                                                                                                               
        ]                                                                                                                                                                                                                                   
    }                                                                                                                                                                                                                                       
} 

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您误解了查询的结构。查询可以是“叶”查询(直接处理单个字段或多个字段)或包装其他查询的“复合”查询,例如 booldis_max 查询。

    common-terms 查询本身就是叶查询,就像 matchmatch_phrasetermrange 查询一样。您不能将 common 查询嵌入到另一个叶查询中。

    match 查询(不是match_phrasematch_phrase_prefix)已与common-terms 查询部分集成,因为它支持cutoff_frequency 参数。这是一个简单的集成:如果您指定cutoff_frequency,那么match 查询将在内部重写为common 查询。如果您想要common-terms 的全部功能,那么您需要直接使用它。

    所以这个match 查询:

    {
       "query": {
          "match": {
             "subject": {
                "query": "some words to query",
                "cutoff_frequency": 0.001
             }
          }
       }
    }
    

    相当于这个common查询:

    {
       "query": {
          "common": {
             "subject": {
                "query": "some words to query",
                "cutoff_frequency": 0.001
             }
          }
       }
    }
    

    不同之处在于在common 查询中,还有许多其他的旋钮可以旋转,例如high_freq_operator

    【讨论】:

    【解决方案2】:

    对于 Elasticsearch 6.4

    例如,将 commonfilter 查询结合使用:

    {
      "explain": true,
      "query": {
        "bool": {
          "must": {
            "common": {
              "task_content": {
                "query": "this is bonsai cool superb",
                "cutoff_frequency": 0.01,
                "high_freq_operator": "and"
              }
            }
          },
          "filter": {
            "term": {
              "subject_id": 2
            }
          }
        }
      },
      "highlight": {
        "fields": {
          "task_content": {}
        }
      }
    }
    

    希望对更新版本有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-05-15
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多