2017-01-22 95 views
2

我已经安装了弹性搜索并在我的本地服务器中安装了插入插件。弹性引擎运行良好。我设置了以下任务:摄取搜索(弹性搜索)不能在PHP中工作

  1. 映射
  2. 索引

现在我被困在搜索,它不工作。它返回空数组。这是我在PHP代码:

public function ingest_processor_searching($query) 
{ 
    $client = $this->client; 
    $params = [ 
     'index' => 'ingest_index', 
     'type' => 'attachment', 
     'body' => [ 
      'query' => [ 
       'match' => [ 
        'textField' => $query, 
       ] 
      ], 
     ], 
    ]; 

    $response = $client->search($params); 
    return $response; 
} 

结果:

{ 
"took": 7, 
"timed_out": false, 
"_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
}, 
    "hits": { 
    "total": 0, 
    "max_score": null, 
    "hits": [] 
} 
} 

但是我有数据为GET http://localhost:9200/ingest_index/attachment/2

{ 
    "_index": "ingest_index", 
    "_type": "attachment", 
    "_id": "2", 
    "_version": 1, 
    "found": true, 
    "_source": { 
    "file_path": "/Users/selimreza/Sites/haber_dev/public/uploads/files/bower.txt", 
    "attachment": { 
     "content_type": "text/plain; charset=ISO-8859-1", 
     "language": "en", 
     "content": "Welcome to Dhaka", 
     "content_length": 18 
    }, 
    "textField": "V2VsY29tZSB0byBEaGFrYQo=" 
    } 
} 

什么是我做了错误?

+0

如果你能证明你的映射? – Kulasangar

回答

0

尝试从'textField' => $query中删除,,因为您未匹配多个值。如果还是不行,请尝试使用term查询,而不是match

$params = [ 
     'index' => 'ingest_index', 
     'type' => 'attachment', 
     'body' => [ 
      'query' => [ 
       'term' => [ <-- have this 
        'textField' => $query <-- try removing the comma 
       ] 
      ], 
     ], 
    ];