"properties":
{
"title":{ "type":"string","index":"analyzed"
"fields":{ "title_exact":{"type":"string","index":"not_analyzed"} }
}, 一,词条查询和全文查询
词条(term)查询和全文(fulltext)查询最大的不同之处是:全文查询首先分析(Analyze)查询字符串,使用默认的分析器分解成一系列的分词,term1,term2,termN,然后从索引中搜索是否有文档包含这些分词中的一个或多个,如果执行的match查询,默认的操作符(operator)是,只要文档的字段值能够匹配任意一个词条,该文档就匹配查询条件;而词条查询是字符的完全匹配,只有当字段的字符完全匹配查询字符串时,ElasticSearch引擎才判定文档匹配查询条件: 词条查询:词条查询不会分析查询条件,只有当词条和查询字符串完全匹配时,才匹配搜索。当在未被分析的字段中进行搜索时,和查询字符串完全匹配的文档会被返回;如果在已分析(Analyzed)的字段中进行搜索,词条必须是小写的单个词条,否则,匹配不到任何文档; 全文查询:ElasticSearch引擎会先分析(analyze)查询字符串,将其拆分成小写的分词,只要已分析的字段中包含词条的任意一个,或全部包含,就匹配查询条件,返回该文档;如果不包含任意一个分词,表示没有任何文档匹配查询条件。
While the full text queries will analyze the query string before executing, the term-level queries operate on the exact terms that are stored in the inverted index.
举个例子,创建索引,并索引文档:
{
"query": {
"wildcard": {
"full_text": "qu*k"
}
}
} 七,正则表达式查询
ElasticSearch引擎支持正则表达式(RegExp)查询,对词条进行查询,这就意味着,在已分析(analyzed)的字符字段上,只能匹配单个分词的正则表达式,引擎把正则表达式应用到字符串字段的分词中,而不是应用到字段最原始的文本:
Elasticsearch will apply the regexp to the terms produced by the tokenizer for that field, and not to the original text of the field.