[英]Using a string to build Query DSL for Elasticsearch
I'm using Meteor (so Javascript, Node, NPM, etc) and would like to provide a simple text input for users to search via Elasticsearch. 我正在使用Meteor(因此使用Javascript,Node,NPM等),并希望为用户提供一个简单的文本输入,以便通过Elasticsearch进行搜索。 I would like to be able to use modifiers on the text like + and "" and search for a specific field.
我希望能够在+和“”之类的文本上使用修饰符并搜索特定字段。 I'm looking for something that can convert a plain text input into Elasticsearch Query DSL.
我正在寻找可以将纯文本输入转换为Elasticsearch Query DSL的东西。
These would be some example queries: 这些将是一些示例查询:
This query would mean that the keyword "tatooine" must exist: 此查询意味着关键字“ tatooine”必须存在:
stormtrooper +tatooine
This would mean that "death star" should be one keyword: 这意味着“死亡之星”应该是一个关键字:
stormtrooper "death star"
This would search for the keyword "bloopers" only in the category field: 这只会在类别字段中搜索关键字“ bloopers”:
stormtrooper category=bloopers
Is there a library that can do this? 有图书馆可以做到这一点吗? Can a generic solution exist or is this why I can't find any existing answers to this?
可以存在通用解决方案吗,或者这就是为什么我找不到对此的任何现有答案?
simple_query_string
would support your query syntax out of the box, except for category=bloopers
which should be category:bloopers
instead, but otherwise it should work: simple_query_string
支持开箱即用的查询语法,但category=bloopers
除外,它应改为category:bloopers
,但否则应该可以:
curl -XPOST localhost:9200/your_index/_search -d '{
"query": {
"simple_query_string": {
"query": "stormtrooper category:bloopers"
}
}
}'
curl -XPOST localhost:9200/your_index/_search -d '{
"query": {
"simple_query_string": {
"query": "stormtrooper +tatooine"
}
}
}'
You can also send the query in the query string directly like this: 您也可以像这样直接在查询字符串中发送查询:
curl -XPOST localhost:9200/your_index/_search?q=stormtrooper%20%22death%20star%22"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.