-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
[Question] Is there a way to convert ES queries to bodybuilder implementation? #294
Comments
I've thought for a while that something like this would be useful, but I think implementing it would be pretty difficult since the api is so flexible. Have you tried using https://bodybuilder.js.org to try to recreate your queries using bodybuilder? You can also ask here if you have a specific complex query, I or someone else may be able to help you along. |
reverse convert is so hard, is @danpaz able to convert this back to {
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"term": {
"content.keyword": {
"value": "小說",
"boost": 2
}
}
},
{
"match": {
"content": "小說"
}
}
]
}
},
"functions": [
{
"field_value_factor": {
"field": "numAuthors",
"factor": 1.2,
"modifier": "log2p",
"missing": 1
}
},
{
"field_value_factor": {
"field": "numArticles",
"modifier": "log2p",
"missing": 1
}
}
]
}
},
"size": 20
} |
@tx0c the function_score query could be expressed in bodybuilder syntax pretty easily, but the functions array is probably best handled separately. Give this a try: let body = bodybuilder()
.query('function_score', b => {
return b
.orQuery('term', 'content.keyword', { value: '小說', boost: 2 })
.orQuery('match', 'content', '小說')
})
.build()
body.query.function_score.functions = [
{
"field_value_factor": {
"field": "numAuthors",
"factor": 1.2,
"modifier": "log2p",
"missing": 1
}
},
{
"field_value_factor": {
"field": "numArticles",
"modifier": "log2p",
"missing": 1
}
}
]
return body |
I've been trying to convert complex ES queries to bodybuilder but it's quite hard to figure it out without much knowledge of the library.
Maybe it would be nice to have a converter from query to bodybuilder to help newcomers to learn how does the lib works 😬
The text was updated successfully, but these errors were encountered: