2015-08-08 81 views
1

我能够为以下弹性的搜索查询得到的数据:弹性搜索:匹配查询没有嵌套布尔工作滤清器

{ 
    "query": { 
    "filtered": { 
     "query": [], 
     "filter": { 
     "bool": { 
      "must": [ 
      { 
       "bool": { 
       "should": [ 
        { 
        "term": { 
         "gender": "malE" 
        } 
        }, 
        { 
        "term": { 
         "sentiment": "positive" 
        } 
        } 
       ] 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

但是,如果我查询中使用“匹配” - 我得到400错误信息状态响应

{ 
    "query": { 
    "filtered": { 
     "query": [], 
     "filter": { 
     "bool": { 
      "must": [ 
      { 
       "bool": { 
       "should": [ 
        { 
        "match": { 
         "gender": "malE" 
        } 
        }, 
        { 
        "term": { 
         "sentiment": "positive" 
        } 
        } 
       ] 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

匹配查询在嵌套bool过滤器中不受支持吗?

由于术语查询在字段的倒排索引中查找确切的术语,我想查询性别数据作为case_insensitive字段 - 我应该尝试哪种方法?

{ 
    "settings": { 
    "index": { 
     "analysis": { 
     "analyzer": { 
      "analyzer_keyword": { 
      "tokenizer": "keyword", 
      "filter": "lowercase" 
      } 
     } 
     } 
    } 
    } 
} 

的映射场性别:指数

设置

{"type":"string","analyzer":"analyzer_keyword"} 
+0

更容易 –

+0

@johnSmith我没有得到你。你的意思是我应该搜索使属性小写,然后通过术语查询进行搜索? –

+0

我的意思是你最有可能的索引对象,并有一个elasticsearch的映射,你可以简单地添加一个属性和一个getter函数到你的对象类,返回小写的名字,将这个字段添加到弹性映射,你没有问题 –

回答

1

原因你得到一个错误400是因为没有match过滤器,只match queries,即使有term queriesterm filters

你的查询可以是这样简单,即不需要一个filtered查询,只需把你的termmatch查询到bool/should

{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "match": { 
      "gender": "male" 
      } 
     }, 
     { 
      "term": { 
      "sentiment": "positive" 
      } 
     } 
     ] 
    } 
    } 
} 
如果你花太多的时间,索引一个小写的属性可能
+0

谢谢。我虽然匹配将在过滤器dsl中工作,因为我使用的是/无输出。除上述以外,我应该使用哪种方法进行不区分大小写的搜索 - 例如“情感”字段中的“非常积极”的集合。 提交的情绪包含 [“积极”,“非常积极”,“消极”,“非常消极”] –