【发布时间】:2014-09-13 11:43:40
【问题描述】:
目前我正在使用 elasticsearch 并尝试“搜索”集群中的文档。这是我没有得到预期结果的地方。我希望得到 4 个返回的结果,因为它们都应该匹配查询关键字“te”。 GET _搜索
{
"query": {
"filtered" : {
"filter" : {
"term" : {
"source_id" : 1
}
},
"query": {
"bool" : {
"must" : {
"term" : { "_all" : "te" }
}
}
}
}
},
"sort": [
{
"date": {
"order": "desc"
}
}
],
"from": 0,
"size": 5
}
当我运行这个查询时,我只得到 2 个结果(而我期待 4 个)。当我删除“查询:{}”部分时,我得到 4 个结果,其中包含以下“主题”字段:
{
"subject": ["Testbericht"]
"subject": ["test"]
"subject": ["Testbericht"]
"subject": ["Test to myself"]
}
查询中的过滤器仅返回来自特定来源的结果(每个查询 1 个来源)。
我的映射:
{
"messages": {
"mappings": {
"message": {
"_id": {
"index": "not_analyzed"
},
"properties": {
"addresses": {
"type": "nested",
"properties": {
"displayname": {
"type": "string"
},
"email": {
"type": "string"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"body": {
"type": "string"
},
"date": {
"type": "date",
"format": "dateOptionalTime"
},
"files": {
"type": "nested",
"properties": {
"size": {
"type": "long"
},
"title": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"folders": {
"type": "nested",
"properties": {
"id": {
"type": "integer"
}
}
},
"size": {
"type": "long"
},
"source_id": {
"type": "integer"
},
"subject": {
"type": "string"
}
}
}
}
}
}
当我尝试搜索 _all = "te" 时得到的结果
{
"subject": ["test"]
"subject": ["Testbericht"]
}
插入文档:
// PHP client from https://github.com/elasticsearch/elasticsearch-php
// $this->search = new Elasticsearch\Client();
// $id is an unique string
// $attributes is an array of the attributes
public function insert($id, array $attributes)
{
$params = [
'index' => self::INDEX,
'type' => self::TYPE,
'id' => $id,
'body' => [
'source_id' => $attributes['source_id'],
'date' => $attributes['date']->format(DateTime::ISO8601),
'size' => $attributes['size'],
'subject' => $attributes['subject'],
'body' => $attributes['body'],
'addresses' => $attributes['addresses'],
'files' => $attributes['files'],
'folders' => $attributes['folders'],
],
];
try
{
$this->search->index($params);
return true;
}
catch(Exception $e)
{
throw new Exception($e->getMessage());
}
return false;
}
【问题讨论】:
-
您在运行查询时得到的两个结果是什么?还有索引时使用的分析器是什么?
-
您已发布查询。请同时发布您的映射。如果没有更多信息,我猜它目前被映射为区分大小写
-
我没有使用任何特定的分析仪,是吗?
标签: php search elasticsearch