gpt4 book ai didi

python - 如何使用 Python 从 bool 表达式生成 elasticsearch 查询?

转载 作者:行者123 更新时间:2023-12-01 09:27:09 25 4
gpt4 key购买 nike

我想“翻译”一个字符串,例如:

A AND (C OR B) AND NOT D

进入 Elasticsearch 查询,例如:

{
"query": {
"bool": {
"must": {
"term": {
"text": "A"
}
},
"must_not": {
"term": {
"text": "D"
}
},
"should": [
{
"term": {
"text": "B"
}
},
{
"term": {
"text": "C"
}
}
],
"minimum_should_match": 1,
"boost": 1
}
}
}

是否存在一些我可以使用的库?感谢任何帮助

谢谢!

最佳答案

确定,根据:

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

我可以进行如下查询:

{
"query": {
"query_string" : {
"default_field" : "text",
"query" : (this AND (submitted OR flowers) AND NOT blight"
}
}
}

效果很好。

关于python - 如何使用 Python 从 bool 表达式生成 elasticsearch 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50289121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com