我有一个带有字段content的索引,下面是一个映射:
{
"properties": {
"content": {
"type": "text",
"analyzer": "english"
}
}
}我有一个简单的搜索查询
curl -X GET 'localhost:9200/idx/_search' -H 'content-type: application/json' -d '{
"query": {
"match": {
"content": "yellow fox"
}
},
"fields": [
"content"
]
}'
{
...
"hits" : {
"hits" : [
{
...
"fields" : {
"content" : [
"Yellow foxes jump"
]
},
}
...
}如何修改我的搜索查询以接收类似分析API提供的内容术语:
curl -X GET 127.0.0.1:9200/_analyze -H 'content-type: application/json' -d '{
"analyzer" : "english",
"text" : "yellow foxes"
}'
{
"tokens" : [
{
"end_offset" : 6,
"position" : 0,
"start_offset" : 0,
"token" : "yellow",
"type" : "<ALPHANUM>"
},
{
"end_offset" : 12,
"position" : 1,
"start_offset" : 7,
"token" : "fox",
"type" : "<ALPHANUM>"
}
]
}通常,所需的搜索查询输出如下所示
{
...
"hits" : {
"hits" : [
{
...
"fields" : {
"content" : [
"Yellow foxes jump"
],
"content_terms": [
"yellow", "fox", "jump"
]
},
}
...
}发布于 2022-04-06 06:29:52
你不需要做任何特殊的搜索条件--因为你已经在做了。当您在匹配查询中给出一个句子时--这个句子本身是用同一个分析器标记的,它被索引了。
这意味着,如果查询是“快速褐狐”--它搜索“快速”“褐色”“狐狸”;在短语查询的情况下,ES也将检查所有术语是否接近。
https://stackoverflow.com/questions/71754863
复制相似问题