0

I have made a PHP client for retrieving data from the index of Elasticsearch. Here is my index file:

<?php

require_once 'init.php';

if(isset($_GET['q'])){
    $q = $_GET['q'];
    $query = $client->search([    
        'body' => [
            'query' => [
                'bool' => [
                    'should' => [
                        'multi_match' => [
                            'fields' => ['district','countrycode','name'],
                            'type' => "phrase_prefix",
                            'query' => $q
                        ]
                    ]
                ]
            ]
        ]       
    ]);
    if($query['hits']['total']>=1){
        $results = $query['hits']['hits'];
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Search | ES</title>
    <link rel="stylesheet" href="css/main.css">
</head>
<body>
    <form action="index2.php" method="get" autocomplete="off">
        <label>
            Search for something
            <input type="text" name="q">
        </label>
        <input type="submit" name="Search">
    </form>

    <?php
        if(isset($results)){
            foreach ($results as $r) {
    ?>

    <div class="result">
        <a href="#<?php echo $r['_id']; ?>">district:<?php echo $r['_source']['district']; ?></a>
        <div class="result-keywords">
            countrycode:<?php echo $r['_source']['countrycode']; ?>
        </div>
        <div class="result-keywords">
            name:<?php echo $r['_source']['name']; ?>
        </div>
    </div>

    <?php
        }
    }
    ?>
</body>
</html>

My index has this structure for a given document(JSON):

{
  "_index": "cities",
  "_type": "city",
  "_id": "35",
  "_version": 1,
  "_score": 0,
  "_source": {
    "id": 35,
    "@timestamp": "2020-03-10T18:24:46.963Z",
    "@version": "1",
    "population": 2168000,
    "district": "Alger",
    "countrycode": "DZA",
    "name": "Alger"
  },
  "fields": {
    "@timestamp": [
      "2020-03-10T18:24:46.963Z"
    ]
  }
}

Now, even when I search for a given input string and it has more than 10 matches, it prints only 10 records in the output. What is the issue here?

preet shah
  • 37
  • 1
  • 10

0 Answers0