[英]PHP Elasticsearch search on two fields
I want to search in two fields. 我想在两个字段中搜索。 One field is passed by PHP and the other is entered by the user in the input field.
一个字段由PHP传递,另一个字段由用户在输入字段中输入。
Can someone help me here? 有人可以帮我吗?
my code: 我的代码:
$params = [
'index' => 'search_documentation',
'type' => 'document',
'body' => [
'size' => 10,
'query' => [
'multi_match' => [
'match' => [
'file.name' => $searchTerm,
'relation.machine' => $machineNumber,
],
],
],
],
];
Unfortunately, it does not work - it always returns 0 results 不幸的是,它不起作用-它总是返回0个结果
so the search is fixed but i have now the problem to search correctly. 所以搜索是固定的,但我现在有正确搜索的问题。 file.name is calling "Anleitung_100_eng.Bedienung.pdf" - if i search for the "keyword" Anleitung or Bedienung they found nothing.. but when i search for example only for "t" then they found that... is this a problem on my query or from the indexing?
file.name调用“ Anleitung_100_eng.Bedienung.pdf”-如果我搜索“关键字” Anleitung或Bedienung,他们一无所获..但是当我仅搜索“ t”时,他们发现...这是一个我的查询或从索引问题?
$params = [
'index' => 'search_' . $machineNumber . '_documentation',
'type' => 'document',
'size' => 500,
'body' => [
'query' => [
'prefix' => [
'file.name' => $searchTerm,
],
],
],
];
any ideas? 有任何想法吗?
Index mapping: 索引映射:
$params = [
'index' => $this->getIndex(),
'body' => [
'mappings' => [
'document' => [
'_source' => [
'excludes' => [
'file_base64'
]
],
'_all' => [
'enabled' => false
],
'properties' => [
'file' => [
'properties' => [
'name' => [
'type' => 'text',
'fields' => [
'keyword' => [
'type' => 'keyword',
'ignore_above' => 256
]
]
],
'extension' => [
'type' => 'keyword'
],
'created' => [
'type' => 'date',
'format' => 'yyy-MM-dd HH:mm:ss'
],
'last_modified' => [
'type' => 'date',
'format' => 'yyy-MM-dd HH:mm:ss'
],
'last_accessed' => [
'type' => 'date',
'format' => 'yyy-MM-dd HH:mm:ss'
],
'path_folder' => [
'type' => 'keyword'
],
'path_file' => [
'type' => 'keyword'
],
'link_file' => [
'type' => 'keyword'
]
]
],
'article' => [
'properties' => [
'number' => [
'type' => 'keyword'
]
]
]
]
],
'meta' => [
'_all' => [
'enabled' => false
],
'properties' => [
'last_modified' => [
'type' => 'date',
'format' => 'yyy-MM-dd HH:mm:ss'
]
]
]
],
'settings' => [
'number_of_shards' => 1,
'number_of_replicas' => 0
]
]
];
ES: ES:
> "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
> }
> }
> }
> }
> }
> }
> }
> }
You need two match
queries: 您需要两个
match
查询:
$params = [
'index' => 'search_documentation',
'type' => 'document',
'body' => [
'size' => 10,
'query' => [
'bool' => [
'must' => [
[ 'match' => [
'file.name' => $searchTerm
]],
[ 'match' => [
'relation.machine' => $machineNumber
]]
]
],
],
],
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.