在不标记关键字的情况下在 elasticsearch 中进行搜索
Search in elasticsearch without tokenizing keywords
{
"from": 0,
"size": 100,
"query": {
"bool": {
"must": [
{
"simple_query_string": {
"query": "template testing",
"fields": [
"tag^8.0",
"title^10.0",
"body^3.0"
],
"flags": -1,
"default_operator": "or",
"analyze_wildcard": false,
"auto_generate_synonyms_phrase_query": false,
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"fuzzy_transpositions": true,
"boost": 1
}
},
],
"filter": [
{
"terms": {
"assetCourse.assetType": [
"epub"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"sort": { "_score": { "order": "desc" }}
}
我想先搜索确切的关键字 'template testing',然后使用 'template' 和 'testing' 进行标记化搜索,但我的查询只搜索 'template' 和 'testing' 分开。请帮助我改进查询。
只需执行一个简单的 匹配 查询,该查询将对结果进行排序,两个术语都出现在顶部,然后是单个术语的结果。
您可以使用此 link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
添加其他参数
{
"query": {
"bool": {
"should": [
{
"match": {
"tag": {
"query": "template testing"
}
}
},
{
"match": {
"title": {
"query": "template testing"
}
}
},
{
"match": {
"body": {
"query": "template testing"
}
}
}
]
}
}
}
{
"from": 0,
"size": 100,
"query": {
"bool": {
"must": [
{
"simple_query_string": {
"query": "template testing",
"fields": [
"tag^8.0",
"title^10.0",
"body^3.0"
],
"flags": -1,
"default_operator": "or",
"analyze_wildcard": false,
"auto_generate_synonyms_phrase_query": false,
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"fuzzy_transpositions": true,
"boost": 1
}
},
],
"filter": [
{
"terms": {
"assetCourse.assetType": [
"epub"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"sort": { "_score": { "order": "desc" }}
}
我想先搜索确切的关键字 'template testing',然后使用 'template' 和 'testing' 进行标记化搜索,但我的查询只搜索 'template' 和 'testing' 分开。请帮助我改进查询。
只需执行一个简单的 匹配 查询,该查询将对结果进行排序,两个术语都出现在顶部,然后是单个术语的结果。 您可以使用此 link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
添加其他参数 {
"query": {
"bool": {
"should": [
{
"match": {
"tag": {
"query": "template testing"
}
}
},
{
"match": {
"title": {
"query": "template testing"
}
}
},
{
"match": {
"body": {
"query": "template testing"
}
}
}
]
}
}
}