Comments (3)
The sort is your problem. You'll notice that your PHP command and Sense commands are actually different, since you are requesting fields
and a sort
value in PHP but not in sense. A 1:1 translation into Sense would be:
GET /inver*/search?fields=_source,name,date&sort:url_date:desc&size=100
{
"filter":{
"term":{
"url":"some value here"
}
},
"query":{
"match":{
"linktext":"some value here"
}
}
}
Which give you similar NULL values in score. This is because you are asking Elasticsearch to only sort by the url_date
, so scores are meaningless...the results come back in the order of the date. If you want scores as well, include the _score
value in the sort
parameter:
In PHP:
$json='{
"filter":{
"term":{
"url":"%s"
}
},
"query":{
"match":{
"linktext":"%s"
}
}
}';
$qStr = sprintf($json,$url,$anchortext);
$params['index'] =get_domain_index($requesturl,"inverted");
$params['type'] ="inverted";
$params['fields'] ="_score,url,referer,linktext";
$params['body'] =$qStr;
$params['sort']="url_date:desc,_score:desc"; // Notice the addition to _score here
$params['size']=100;
try{
$rc = $GLOBALS['e']->search($params);
}catch (Exception $error){
echo "Not found\n";
//echo $error." Error Getting record\n";
}
And in Sense:
GET /inver*/search?fields=_source,name,date&sort:url_date:desc,_score:desc&size=100
{
"filter":{
"term":{
"url":"%s"
}
},
"query":{
"match":{
"linktext":"%s"
}
}
}
That should fix your problem :)
Now, with that said, you should probably be specifying the sort value in the query body rather than the URL parameters, since it allows more configuration:
$json='{
"filter":{
"term":{
"url":"%s"
}
},
"query":{
"match":{
"linktext":"%s"
}
},
"sort": [
{
"url_date": {
"order": "desc"
}
},
{
"_score": {
"order": "desc"
}
}
]
}';
$qStr = sprintf($json,$url,$anchortext);
$params['index'] =get_domain_index($requesturl,"inverted");
$params['type'] ="inverted";
$params['fields'] ="_score,url,referer,linktext";
$params['body'] =$qStr;
$params['size']=100;
try{
$rc = $GLOBALS['e']->search($params);
}catch (Exception $error){
echo "Not found\n";
//echo $error." Error Getting record\n";
}
from elasticsearch-php.
WOW!!! What a great answer.. Makes perfect sense. Thank you very very much
from elasticsearch-php.
No problem, glad to help :)
Closing this ticket, feel free to reopen or make a new one if you have any other issues.
from elasticsearch-php.
Related Issues (20)
- $es_client->index($params) Response nginx 405 HOT 1
- Elasticsearch behind Proxy Server HOT 2
- Response object is empty after logging
- Logs are not sent in Laravel queues when use async log HOT 2
- Changelog for latest version 8.10.0 HOT 1
- 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
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.