我想问一下如何使用弹性搜索过滤特定数据的简单1个字符 A-Z
所以..例如我有数据
我想获得所有以字符开头(不包含)的结果,例如" A" 。结果是
我在这里发现我应该创建新的分析器analyzer_startswith并设置如下。怎么了?现在我得到 0结果
Elastica .yml config
fos_elastica:
clients:
default: noImportantInfo
indexes:
bundleName:
client: default
finder: ~
settings:
index:
analysis:
analyzer:
analyzer_startswith:
type: custom
tokenizer: keyword
filter:
- lowercase
types:
content:
properties:
id:
type: integer
elasticaPriority:
type: integer
title:
type: string
analyzer: another_custom_analyzer
fields:
raw:
type: string
index: not_analyzed
title_ngram:
type: string
analyzer: analyzer_startswith
property_path: title
谢谢
答案 0 :(得分:0)
您可以使用前缀查询,请参阅此处https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-prefix-query.html:
GET /_search
{ "query": {
"prefix" : { "user" : "ki" }
}
}
答案 1 :(得分:0)
谢谢我使用了前缀及其工作。
我将索引设置为not_analyzed并使用Prefix查找字符串中的第一个字符。
title_ngram:
type: string
property_path: title
index: not_analyzed
现在有没有其他方法可以为我的" title_ngram" 应用标准搜索?因为我想在" title_ngram"
中搜索单个1个字符以及全文搜索答案 2 :(得分:0)
试试这个
GET /content/_search
{
"query": {
"match": {
"title": "A"
}
},
"sort": "title.raw"
}
有关更多信息,请参阅以下链接 https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-fields.html