Comments (12)
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.
Very thanks.
I used 0.9 but i'm migrating 1 version
For percolator i must create a mapping ?
thanks
from elasticsearch-php.
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.
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.
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.
Oh thanks, very thanks ;)
from elasticsearch-php.
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.
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.
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.
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.
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.
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)
- Path in hosts configuration is ignored HOT 2
- check the index exsists ,it have a error HOT 1
- Connecting to Elasticsearch v8.x using the v7.17.x client HOT 1
- Received a 403 Forbidden error when attempting to index HOT 1
- `Response\Elasticsearch::offsetGet()` return type declaration HOT 2
- Need a new Release 6.8.3 HOT 4
- ServerError was not handled correctly. HOT 2
- Add support for Elasticsearch with Bulk API and data stream HOT 1
- How to pass specific characters password to ElasticSearch through Sulu/ArticleBundle HOT 5
- [Request feedback] Looking for feedback about the UX experience
- Calling static trait method ... is deprecated HOT 1
- Inquiries about version use HOT 2
- [Proposal] Add a mapTo(class) function for map ES|QL response into objects HOT 1
- Why Can't I update the mapping with Laravel Scout? HOT 1
- 使用PHP GET方法,不能获取到文档内容 HOT 4
- please help me change the php code from pagination from + size to search_after HOT 5
- failed to get the last sort using search_after HOT 1
- Add OpenTelemetry support HOT 1
- will elasticsearch-php pre-open the urls on the page when I visit it? HOT 3
- "Type: illegal_argument_exception Reason: "Fielddata is disabled on [pageCategory] in [elastic_web_index]. Text fields are not optimised for operations that require per-document field data like aggregations HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-php.