4

I have installed elastic search and also install ingest plugin in my local server. Elastic engine is running nicely. I set up the following tasks:

  1. mapping
  2. indexing

Now I am stuck in searching, it's not working. It returns null array. Here is my code in 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;
}

Result:

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

But I have Data for the 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="
  }
}

What is the mistake I did?

halfer
  • 19,824
  • 17
  • 99
  • 186
Selim Reza
  • 683
  • 1
  • 11
  • 31

1 Answers1

2

Try removing the , from your 'textField' => $query since you aren't matching multiple values. If it still doesn't work, try using the term query instead of match:

 $params = [
        'index' => 'ingest_index',
        'type' => 'attachment',
        'body' => [
            'query' => [
                'term' => [ <-- have this
                    'textField' => $query <-- try removing the comma
                ]
            ],
        ],
    ];
Kulasangar
  • 9,046
  • 5
  • 51
  • 82