我同意用户@Lue
E进行了更多修改,并尝试了一种简单的关键字方法,但给了我一些问题,因此我修改了
keyword在自己的自定义分析器中使用标记器的方法,该方法可以解决您的大多数用例。
使用自定义分析器进行索引定义
{ "settings": { "analysis": { "analyzer": { "my_custom_analyzer": { "type": "custom", "tokenizer": "keyword", --> to make it searchable "filter": [ "lowercase", --> case insensitive search "trim" --> remove extra spaces ] } } } }, "mappings": { "properties": { "mathformula": { "type": "text", "analyzer": "my_custom_analyzer" } } }}索引样本文档
{ "mathformula" : "(a+b)^2 = a^2 + b^2 + 2ab" }{ "mathformula" : "a2+b2 = c2"}搜索查询(匹配查询,使用相同的索引时间分析器)
{ "query": { "match" : { "mathformula" : { "query" : "a2+b2 = c2" } } }}搜索结果仅包含第一个索引文档
"hits": [ { "_index": "so_math", "_type": "_doc", "_id": "1", "_score": 0.6931471, "_source": { "mathformula": "a2+b2 = c2" } } ]


