basemkhirat / elasticsearch

The missing elasticsearch ORM for Laravel, Lumen and Native php applications
MIT License
401 stars 130 forks source link

Not Getting Result With Elastic Search #88

Open rahultrivedi20 opened 6 years ago

rahultrivedi20 commented 6 years ago

Hi There, I am not getting elastic search using distance query. Could you please help on this. Please do find my code as well as:

es.php

indices' => [

    'vehicle_index' => [

        "aliases" => [
            "vehicle_index_alias"
        ],
        'settings' => [
            "number_of_shards" => 1,
            "number_of_replicas" => 1,
        ],
        'mappings' => [
            'vehicle_schema' => [
                "properties" => [
                    'uuid' => [
                        'type' => 'text'
                    ],
                    'vehicle_id' => [
                        'type' => 'text'
                    ],
                    'location' => [
                        'type' => 'geo_point',
                    ],
                    'vehicle_number' => [
                        'type' => 'text',
                    ],
                    'vehicle_name' => [
                        'type' => 'text'
                    ],
                    'vehicle_model' => [
                        'type' => 'text'
                    ],
                    'registration_number' => [
                        'type' => 'text'
                    ],
                    'qr_code' => [
                        'type' => 'text'
                    ],
                    'latitude' => [
                        'type' => 'double'
                    ],
                    'longitude' => [
                        'type' => 'double'
                    ],
                    'battery_life' => [
                        'type' => 'float'
                    ],
                    'travel_miles' => [
                        'type' => 'float'
                    ],
                    'vehicle_description' => [
                        'type' => 'text'
                    ],
                    'registration_date' => [
                        'type' => 'date'
                    ],
                    'puc_validity_date' => [
                        'type' => 'date'
                    ],
                    'insurance_expiry_date' => [
                        'type' => 'date'
                    ],
                    'in_use' => [
                        'type' => 'boolean'
                    ],
                    'status' => [
                        'type' => 'text'
                    ],
                    'vehicle_document' => [
                        'type' => 'object',
                        "properties" => [
                            'id' => [
                                'type' => 'integer'
                            ],
                            'filename' => [
                                'type' => 'text'
                            ],
                            'url' => [
                                'type' => 'text'
                            ],
                        ]
                    ],
                ]
            ],
        ]

Near By Query: $lat = 23.162534782609; $long = 72.666932907733; $qtr = $documents->distance("location", ["lat" => $lat, "lon" => $long], "5km")->get();

Result: Basemkhirat\Elasticsearch\Collection Object ( [items:protected] => Array ( )

[total] => 0
[max_score] => 
[took] => 6
[timed_out] => 
[scroll_id] => 
[shards] => stdClass Object
    (
        [total] => 1
        [successful] => 1
        [skipped] => 0
        [failed] => 0
    )

)

My Elatic Schema:

{ "took" : 5, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 9, "max_score" : 1.0, "hits" : [ { "_index" : "vehicle_index", "_type" : "vehicle_schema", "_id" : "Y4wf-WMBDMjtrIQNbdtm", "_score" : 1.0, "_source" : { "uuid" : "8fbcfb3e-b560-41b2-b7ae-117afb0fb5e0", "vehicle_id" : "VEH_1", "vehicle_number" : "VEHICLE_KJ01", "id" : 1, "vehicle_name" : "Jeevn Dash", "vehicle_model" : "GJHTUP_001", "registration_number" : "REG_HTF_001", "qr_code" : "QRC_001", "latitude" : 23.119056521739, "longitude" : 72.619688605156, "battery_life" : 89, "travel_miles" : 87, "vehicle_description" : null, "status" : "Active" } }, { "_index" : "vehicle_index", "_type" : "vehicle_schema", "_id" : "ZIwf-WMBDMjtrIQNbtt4", "_score" : 1.0, "_source" : { "uuid" : "6279e35f-bc4c-428e-aeec-df37d85380c5", "vehicle_id" : "VEH_2", "vehicle_number" : "VEHICLE_KJ02", "id" : 2, "vehicle_name" : "Jeevn Dash", "vehicle_model" : "GJHTUP_002", "registration_number" : "REG_HTF_002", "qr_code" : "QRC_002", "latitude" : 23.162534782609, "longitude" : 72.666932907733, "battery_life" : 51, "travel_miles" : 81, "vehicle_description" : null, "status" : "Active" } }, { "_index" : "vehicle_index", "_type" : "vehicle_schema", "_id" : "ZYwf-WMBDMjtrIQNb9ul", "_score" : 1.0, "_source" : { "uuid" : "ac8dceaf-4c0b-47bd-b6a2-beedcabdefc8", "vehicle_id" : "VEH_3", "vehicle_number" : "VEHICLE_KJ03", "id" : 3, "vehicle_name" : "Jeevn Dash", "vehicle_model" : "GJHTUP_003", "registration_number" : "REG_HTF_003", "qr_code" : "QRC_003", "latitude" : 23.133549275362, "longitude" : 72.635436706015, "battery_life" : 53, "travel_miles" : 119, "vehicle_description" : null, "status" : "Active" } }, { "_index" : "vehicle_index", "_type" : "vehicle_schema", "_id" : "Zowf-WMBDMjtrIQNcNts", "_score" : 1.0, "_source" : { "uuid" : "0301b2c7-f4ac-4853-966f-ded488bd7e93", "vehicle_id" : "VEH_4", "vehicle_number" : "VEHICLE_KJ04", "id" : 4, "vehicle_name" : "Jeevn Dash", "vehicle_model" : "GJHTUP_004", "registration_number" : "REG_HTF_004", "qr_code" : "QRC_004", "latitude" : 23.061085507246, "longitude" : 72.556696201719, "battery_life" : 28, "travel_miles" : 115, "vehicle_description" : null, "status" : "Active" } }, { "_index" : "vehicle_index", "_type" : "vehicle_schema", "_id" : "Z4wf-WMBDMjtrIQNcdsc", "_score" : 1.0, "_source" : { "uuid" : "ff34045c-0203-4be9-ab8e-0c2e46da4307", "vehicle_id" : "VEH_5", "vehicle_number" : "VEHICLE_KJ05", "id" : 5, "vehicle_name" : "Jeevn Dash", "vehicle_model" : "GJHTUP_005", "registration_number" : "REG_HTF_005", "qr_code" : "QRC_005", "latitude" : 23.061085507246, "longitude" : 72.556696201719, "battery_life" : 20, "travel_miles" : 133, "vehicle_description" : null, "status" : "Active" } }, { "_index" : "vehicle_index", "_type" : "vehicle_schema", "_id" : "aIwf-WMBDMjtrIQNcdvE", "_score" : 1.0, "_source" : { "uuid" : "0f274962-3337-4060-936f-6c3500f15258", "vehicle_id" : "VEH_6", "vehicle_number" : "VEHICLE_KJ06", "id" : 6, "vehicle_name" : "Jeevn Dash", "vehicle_model" : "GJHTUP_006", "registration_number" : "REG_HTF_006", "qr_code" : "QRC_006", "latitude" : 23.148042028986, "longitude" : 72.651184806874, "battery_life" : 43, "travel_miles" : 67, "vehicle_description" : null, "status" : "Active" } }, { "_index" : "vehicle_index", "_type" : "vehicle_schema", "_id" : "aYwf-WMBDMjtrIQNcttz", "_score" : 1.0, "_source" : { "uuid" : "08ca2c17-90f9-4d3d-a852-950e2539a856", "vehicle_id" : "VEH_7", "vehicle_number" : "VEHICLE_KJ07", "id" : 7, "vehicle_name" : "Jeevn Dash", "vehicle_model" : "GJHTUP_007", "registration_number" : "REG_HTF_007", "qr_code" : "QRC_007", "latitude" : 23.148042028986, "longitude" : 72.651184806874, "battery_life" : 57, "travel_miles" : 75, "vehicle_description" : null, "status" : "Active" } }, { "_index" : "vehicle_index", "_type" : "vehicle_schema", "_id" : "aowf-WMBDMjtrIQNc9uf", "_score" : 1.0, "_source" : { "uuid" : "7afcc889-5026-4b27-8661-26a2461e0ca9", "vehicle_id" : "VEH_8", "vehicle_number" : "VEHICLE_KJ08", "id" : 8, "vehicle_name" : "Jeevn Dash", "vehicle_model" : "GJHTUP_008", "registration_number" : "REG_HTF_008", "qr_code" : "QRC_008", "latitude" : 23.177027536232, "longitude" : 72.682681008593, "battery_life" : 63, "travel_miles" : 92, "vehicle_description" : null, "status" : "Active" } }, { "_index" : "vehicle_index", "_type" : "vehicle_schema", "_id" : "a4wf-WMBDMjtrIQNdNs7", "_score" : 1.0, "_source" : { "uuid" : "7a6e6adc-4527-4479-bf9d-cc27e6b188b6", "vehicle_id" : "VEH_9", "vehicle_number" : "VEHICLE_KJ09", "id" : 9, "vehicle_name" : "Jeevn Dash", "vehicle_model" : "GJHTUP_009", "registration_number" : "REG_HTF_009", "qr_code" : "QRC_009", "latitude" : 23.07557826087, "longitude" : 72.572444302578, "battery_life" : 58, "travel_miles" : 116, "vehicle_description" : null, "status" : "Active" } } ] } }