感谢帮助
$params = [
'index' => 'search_dokumentation',
'type' => 'document',
'size' => 500,
'body' => [
'query' => [
'bool' => [
'should' => [
'wildcard' => [
'file.name' => '*' . strtolower($searchTerm) . '*',
],
],
'minimum_should_match' => 1,
],
],
'sort' => [
'_score' => [
'order' => 'asc',
],
],
],
"mappings": {
"meta": { "_all": { "enabled": false }, "properties": { "last_modified": { "type": "date", "format": "yyy-MM-dd HH:mm:ss" }, "update_date": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "document": { "_all": { "enabled": false }, "_source": { "excludes": [ "file.content_base64" ] }, "properties": { "article": { "properties": { "number": { "type": "keyword" } } }, "file": { "properties": { "content_base64": { "type": "text" }, "create_date": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "created": { "type": "date", "format": "yyy-MM-dd HH:mm:ss" }, "extension": { "type": "keyword" }, "last_accessed": { "type": "date", "format": "yyy-MM-dd HH:mm:ss" }, "last_modified": { "type": "date", "format": "yyy-MM-dd HH:mm:ss" }, "link_file": { "type": "keyword" }, "link_folder": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "name": { "type": "text", "fields": { "decompound": { "type": "text", "analyzer": "my_decompound" }, "keyword": { "type": "keyword", "ignore_above": 256 }, "simple": { "type": "text", "analyzer": "simple" } } }, "path_file": { "type": "keyword" }, "path_folder": { "type": "keyword" }, "path_folder_short": { "type": "keyword" }, "permissions": { "type": "long" }, "size": { "type": "long" }, "version": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "relation": { "properties": { "machine": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "plant": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "type": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } } }
答案 0 :(得分:0)
从您的映射中,您似乎正在将file.name
用于standard analyzer
。因此,match
查询应该适合您。这是一个示例:
PUT newindex/_doc/1
{
"file.name": "hello + friend"
}
GET newindex/_doc/_search
{
"query": {
"match": {
"file.name": "hello + friend"
}
}
}
standard analyzer
实际上将删除特殊字符。因此,如果您_analyze
术语“你好+朋友”,您会看到它将其分为两个术语。
GET _analyze
{
"text": ["hello + friend"],
"analyzer": "standard"
}
结果:
{
"tokens": [
{
"token": "hello",
"start_offset": 0,
"end_offset": 5,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "friend",
"start_offset": 8,
"end_offset": 14,
"type": "<ALPHANUM>",
"position": 1
}
]
}
编辑:
对于将文件名“ Betriebsanleitung_Schere + Stangenmagazin_V3.5.pdf”与部分匹配项(术语“奇怪”)进行匹配的用例,可以将query_string
与一些通配符一起使用。
{
"query": {
"query_string": {
"query": "*stangen*"
}
}
}