我正在尝试对连续类型的字段进行搜索查询。我也配置了同义词。我没有得到搜索查询的任何结果。
synonyms.txt的内容
iit, indian institute of technology
iitg, indian institute of technology guwahati
创建指数机构:
curl -XDELETE 'http://localhost:9200/institutes/'
curl -XPUT 'http://localhost:9200/institutes/' -d '{
"settings": {
"index": {
"analysis": {
"analyzer": {
"suggest_synonyms": {
"type": "custom",
"tokenizer": "whitespace",
"filter": ["lowercase","my_synonyms"]
}
},
"filter" : {
"my_synonyms" : {
"type" : "synonym",
"synonyms_path" : "synonyms.txt"
}
}
}
}
},
"mappings": {
"institute" : {
"properties" : {
"name" : { "type" : "string","index": "not_analyzed" },
"name_suggest" : {
"type" : "completion",
"index_analyzer" : "suggest_synonyms",
"search_analyzer" : "suggest_synonyms",
"preserve_position_increments": false,
"preserve_separators": false
}
}
}
}
}'
参赛作品:
curl -X PUT 'localhost:9200/institutes/institute/3?refresh=true' -d '
{
"name" : "iitg",
"name_suggest" : "iitg"
}'
curl -X PUT 'localhost:9200/institutes/institute/2?refresh=true' -d '
{
"name" : "indian institute of technology guwahati",
"name_suggest" : "indian institute of technology guwahati"
}'
curl -X PUT 'localhost:9200/institutes/institute/1?refresh=true' -d '
{
"name" : "indian institute of technology",
"name_suggest" : "indian institute of technology"
}'
不起作用的查询:
curl -X POST 'localhost:9200/institutes/_search?pretty' -d '
{
"query" : {
"filtered" : {
"filter" : {
"terms" : {
"name_suggest" : ["iit"]
}
}
}
}
}'
curl -X POST 'localhost:9200/institutes/_search?pretty' -d '
{
"query": {
"match": {
"name_suggest": "iitg"
}
}
}'
curl -X POST 'localhost:9200/institutes/_search?pretty' -d '
{
"query": {
"match": {
"name_suggest": "indian institute of technology"
}
}
}'
我正在对name_suggest进行查询。在我的生产数据库中我没有列name_suggest这是我正在测试和尝试的东西。
上面的所有三个查询都没有返回任何结果。请告诉我这里做错了什么。
更新:添加了_analyze的输出
curl -XGET' localhost:9200 / institutes / _analyze?analyzer = suggest_synonyms& pretty = 1' -d' 印度理工学院guwahati '
{
"tokens" : [ {
"token" : "iit-g",
"start_offset" : 1,
"end_offset" : 40,
"type" : "SYNONYM",
"position" : 1
}, {
"token" : "iitg",
"start_offset" : 1,
"end_offset" : 40,
"type" : "SYNONYM",
"position" : 1
}, {
"token" : "indian",
"start_offset" : 1,
"end_offset" : 7,
"type" : "SYNONYM",
"position" : 1
}, {
"token" : "institute",
"start_offset" : 8,
"end_offset" : 17,
"type" : "SYNONYM",
"position" : 2
}, {
"token" : "of",
"start_offset" : 18,
"end_offset" : 20,
"type" : "SYNONYM",
"position" : 3
}, {
"token" : "technology",
"start_offset" : 21,
"end_offset" : 31,
"type" : "SYNONYM",
"position" : 4
}, {
"token" : "guwahati",
"start_offset" : 32,
"end_offset" : 40,
"type" : "SYNONYM",
"position" : 5
} ]
}
感谢您提前不对该问题进行投票。