Coder Social home page Coder Social logo

Comments (12)

polyfractal avatar polyfractal commented on September 23, 2024

What version of Elasticsearch are you using? The documentation you linked to is from 0.90.

For 1.0, this is how you would register a percolator query and then percolate a document:

// Register a query into the percolator
$params = [
    'index' => 'my_index',
    'type' => '.percolator',
    'id' => 1,
    'body' => [
        'query' => [
            'match' => [
                'phrase' => [
                    'query' => 'some query here'
                ]
            ]
        ],
        'percolator_metadata' => 'red',
        'more_metadata' => [1,2,3]
    ]
];
$client->index($params);

// Now percolate a doc
$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'body' => [
        'doc' => [
            'some_field' => 'some values'
        ],
        'filter' => [
            'term' => [
                'percolator_metadata' => 'red'
            ]
        ]
    ]
];
$results = $client->percolate($params);

from elasticsearch-php.

timothylhuillier avatar timothylhuillier commented on September 23, 2024

Very thanks.

I used 0.9 but i'm migrating 1 version

For percolator i must create a mapping ?

thanks

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 23, 2024

You can, but it isn't required. Elasticsearch will auto-detect the mapping based on the query that you register. I don't normally create a mapping first, usually the auto-detected mapping is fine.

from elasticsearch-php.

timothylhuillier avatar timothylhuillier commented on September 23, 2024

Oki thanks,

because, my percolate used geopoint filter :

    $paramsEs['index'] = 'ptf';
    $paramsEs['type']  = '.percolator';
    $paramsEs['id']  = $alert->id;
    $paramsEs['body'] = [

        "filter" => [
            // le filtre utilise la geolocalisation et la distance
            "geo_distance" => [
                "distance" => $distance,
                "location" => [
                    "lat" => $lat,
                    "lon" => $lng
                ]
            ]
        ]
    ];

    $percolate = Es::index($paramsEs);

But the code isn't working :

{"error":"PercolatorException[[ptf] failed to parse query [13]]; nested: QueryParsingException[[ptf] Failed to parse]; nested: NullPointerException; ","status":500}

NB : Es::index() because à i'm using laravel-elasticsearch package

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 23, 2024

Try this, I think your query is just incorrectly formatted (you need a "query" clause in the registered percolator, which means you will need a filtered query to wrap your geo_distance filter):

$paramsEs['body'] = [
    "query" => [
        "filtered" => [
            "filter" => [
                // le filtre utilise la geolocalisation et la distance
                "geo_distance" => [
                    "distance" => $distance,
                    "location" => [
                        "lat" => $lat,
                        "lon" => $lng
                    ]
                ]
            ]
        ]
    ]
];

from elasticsearch-php.

timothylhuillier avatar timothylhuillier commented on September 23, 2024

Oh thanks, very thanks ;)

from elasticsearch-php.

timothylhuillier avatar timothylhuillier commented on September 23, 2024

So, If i want tu use percolate i must do :

    $paramsEs['index'] = 'ptf';
    $paramsEs['type']  = 'products';
    $paramsEs['body'] = [
        "doc" => [
            "geo_distance" => [
                "location" => [
                    "lat" => $lat,
                    "lon" => $lng
                ]
            ]
        ]
    ];

    $percolate = Es::percolate($paramsEs);

It say me that it's oki succefful 5 but I had only 1 products and nothing matches

Thanks

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 23, 2024

The "OK Successful 5" refers to all five shards in your index responded "OK". That simply means your cluster is healthy, and has nothing to do with the search results.

The reason you are getting no search results is because your percolated document doesn't match the percolator. Specifically, it doesn't have a "location" field where the registered query expects. Try this:

$paramsEs['index'] = 'ptf';
    $paramsEs['type']  = 'products';
    $paramsEs['body'] = [
        "doc" => [
              "location" => [
                  "lat" => $lat,
                  "lon" => $lng
              ]
        ]
    ];

    $percolate = Es::percolate($paramsEs);

Your registered percolator is performing a geo_distance filter, and looking for the field called location to extract the lat and lon. So you need to provide a document that is structured appropriately.

from elasticsearch-php.

timothylhuillier avatar timothylhuillier commented on September 23, 2024

Thanks for explication but it is not working

I still have not matchs event with example.

$lat = 48.856614;
$lng = 2.3522220000000003;
$distance = 3;

This my index perculator :

    $paramsEs['index'] = 'ptf';
    // indique que le type est un perlocator
    $paramsEs['type']  = '.percolator';
    $paramsEs['id']  = $alert->id;
    $paramsEs['body'] = [
        "query" => [
            "filtered" => [
                "filter" => [
                    // le filtre utilise la geolocalisation et la distance
                    "geo_distance" => [
                        "distance" => $distance,
                        "location" => [
                            "lat" => $lat,
                            "lon" => $lng
                        ]
                    ]
                ]
            ]
        ]
    ];

    // enregistre le percolate
    Es::index($paramsEs);

And this my percolate

    $paramsEs['index'] = 'ptf';
    $paramsEs['type']  = 'products';
    $paramsEs['body'] = [
        "doc" => [
            "location" => [
                "lat" => $lat,
                "lon" => $lng
            ]
        ]
    ];

    // enregistre le percolate
    $percolate = Es::percolate($paramsEs);

EDIT : I'm sory it's working, Thank you soo much

from elasticsearch-php.

timothylhuillier avatar timothylhuillier commented on September 23, 2024

I have one point that i din't understand

Percolate return a match with _id 14 while the _id is 13.

Do you Know, why ?

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 23, 2024

Hard to say without seeing the full recreation (docs, queries and percolators), but remember that the Percolator returns the _id of the matching percolator query, not the id of the document.

from elasticsearch-php.

timothylhuillier avatar timothylhuillier commented on September 23, 2024

Oh oki thanks,

So can i register userId in percolator and return userId when percolator is matching ?
because I think that it's possible in document but i don't know in query (perculator).

from elasticsearch-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.