我已使用以下设置配置了我的索引,并且 matchAll 查询结果在 IPRANGE 字段中具有值“试用”。
设置:
{
"settings" : {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 5
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings" : {
"users" : {
"properties" : {
"IPRANGE" : {
"type" : "string",
"analyzer" : "autocomplete"
}
}
}
},
refresh_interval: "1000"
}
但是当我使用以下有效负载进行搜索时,它不会返回结果,即 0 次点击。
网址:
http://xxxxxx:9200/db2/users/_search
有效负载:
{
"query": {
"match": {
"IPRANGE": "tr"
}
}
}
可能是什么问题?
最佳答案
您如何为文档编制索引?这是一个有效的示例:
我更改了映射,以便使用 autocomplete
分析器来索引 IPRANGE
字段,当搜索该字段时,将使用默认分析器(您不需要想要以同样的方式分割搜索词)。
/POST http://localhost:9200/test
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 5
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"users": {
"properties": {
"IPRANGE": {
"type": "string",
"search_analyzer": "autocomplete"
}
}
}
}
}
索引文档
/POST http://localhost:9200/test/users/1/
{
"IPRANGE":"trial"
}
搜索请求:
/POST http://localhost:9200/test/users/_search
{
"query": {
"match": {
"IPRANGE": "tr"
}
}
}
返回以下结果:
{
took: 10
timed_out: false
_shards: {
total: 5
successful: 5
failed: 0
}
hits: {
total: 1
max_score: 0.30685282
hits: [
{
_index: test
_type: users
_id: 1
_score: 0.30685282
_source: {
IPRANGE: trial
}
}
]
}
}
关于java - ElasticSearch Edge-ngram 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25529020/