-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup Terms query code #1765
Cleanup Terms query code #1765
Conversation
4a616cf
to
62ceefb
Compare
*/ | ||
public function setTerms(string $key, array $terms): self | ||
public static function buildTermsLookup(string $field, string $index, string $id, string $path): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say: yes :)
It is an helper function to directly create a Terms lookup query, without first creating the Terms query, and then assign the lookup settings.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the constructor should then allow this? ;-)
But I'm fine going with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that the constructor covers the "base" case, while a specific method can configure the "lookup" settings.
Having an helper doing it in one single go, helps in this direction :)
Saying it here as, if we agree, this could be the standard for other query classes too. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same as:
$terms = (new Terms($field))->setTermsLookup($index, $id, $path);
I did not test if the above works.
What I worry is that we add methods which do not necessarily simplify the code on the user end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the above is the same of Terms::buildTermsLookup($field, $index, $id, $path)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it is still needed? Or could we put the above for example as a doc comment for the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I removed the helper function.
I guess looking at the Terms methods it is clear how to use the setTermsLookup()
:)
See: #1767
62ceefb
to
17c3b02
Compare
* | ||
* @param string $key Terms key | ||
* @param array $terms Terms list | ||
* @var string[]|null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is string[]
really the only correct type?
Wouldn't be string[]|int[]
be equally correct (and all the other references in this class)?
For ElasticSearch, AFAIK, it doesn't matter if I send a number as string or an actual int, both equally work well.
I'm asking because in the process of the upgrade, using static analyzers, now complains passing integers to these methods but from my experience technically this isn't strictly required?
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested it but I think you are correct @mfn That both will work. I assume even a double could be passed in and just works? Could you test it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I did some testing with the terms
query directly in the Kibana console and my findings are that string, int and float (i.e. the JavaScript equivalent) work equally well.
E.g. if I've field of type long
and I use it in a simple query like this:
GET …/_search
{
"query": {
"terms": {
"some_field": [
1234
]
}
}
}
Whether I use "1234"
, 1234
or 1234.0
did not make any difference.
Note that the same applies to term
query too, I tested this:
GET …/_search
{
"query": {
"term": {
"some_field": {
"value": 1234
}
}
}
}
(Ok realized the Term
query class does not use these specific type hints, so not affected by this.)
I think since fields can have the type double
, yes, I guess float
is also appropriate to include (though not sure how useful a term search for this would be compared to e.g. ranges, but who knows).
Do you think this is good enough warranted a phpdoc change here, i.e. to string[]|int[]|float[]
? Annoyingly long btw :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfn Yes! Can you open a PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Continuing in #1872
As shown in ruflin#1765 (comment) , ElasticSearch accepts all of them
As shown in ruflin#1765 (comment) , ElasticSearch accepts all of them
As shown in ruflin#1765 (comment) , ElasticSearch accepts all of them
As shown in ruflin#1765 (comment) , ElasticSearch accepts all of them
…1872) As shown in #1765 (comment) , ElasticSearch accepts all of them Note: the change of `public function addTerm` was not previously discussed, but is made for consistency, however poses a breaking change if someone extended this class previously => https://3v4l.org/Ws5bM
No description provided.