ElasticsSearch——Query String
来源:互联网 发布:饥荒 熔炉 知乎 编辑:程序博客网 时间:2024/05/18 03:42
之前一直觉的QueryString这种查询方式挺好用的,用它的主要场合就是对同一个词针对多字段可以查询,这好像是其他方式所不支持的。今天一个Bug 出来才发现,原来还有很多不了解的地方。
queryString 是能够自动解析查询的字符串的,而且其中还可以使用正则表达式。既方便,但是对于不用这个功能的我,就显得尤为没有必要,因为我的字符串如果包含了他已经实现定义有特定意义的字符,就会报错,因为他误会我的意思了。
Query String Queryedit
On this page
- Query string syntax
- Elasticsearch Reference:
- Getting Started
- Setup
- Breaking changes
- API Conventions
- Document APIs
- Search APIs
- Aggregations
- Indices APIs
- cat APIs
- Cluster APIs
- Query DSL
- Query and filter context
- Match All Query
- Full text queries
- Match Query
- Multi Match Query
- Common Terms Query
- Query String Query
- Simple Query String Query
- Term level queries
- Compound queries
- Joining queries
- Geo queries
- Specialized queries
- Span queries
- Minimum Should Match
- Multi Term Query Rewrite
- Mapping
- Analysis
- Modules
- Index Modules
- Testing
- Glossary of terms
- Release Notes
A query that uses a queryparserin order to parse its content.
也就是说这种查询方式有一个自己的解析器会解析输入的查询字符串。
Multi Fieldedit
The query_string
query can also run against multiple fields. Fields can be provided via the "fields"
parameter (example below).
The idea of running the query_string
query against multiple fields is to expand each query term to an OR clauselike this:
field1:query_term OR field2:query_term | ...
For example, the following query
{ "query_string" : { "fields" : ["content", "name"], "query" : "this AND that" }}
matches the same words as
{ "query_string": { "query": "(content:this OR name:this) AND (content:that OR name:that)" }}
Reserved characters 保留字符edit
If you need to use any of the characters which function as operators in your query itself (and not as operators), then you should escape them with a leading backslash. For instance, to search for (1+1)=2
, you would need to write your query as \(1\+1\)\=2
.
The reserved characters are: + - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /
Failing to escape these special characters correctly could lead to a syntax error which prevents your query from running.
还是改成短语匹配吧,有时间再好好研究规避保留字符的方法。
现在贴上将字符串中所有正则表达式的字符进行转义的方法
public class StringHelper { /// <summary> /// 转义字符串中所有正则特殊字符 /// </summary> /// <param name="input">传入字符串</param> /// <returns></returns> public static string FilterString(string input) { input = input.Replace("\\", "\\\\");//先替换“\”,不然后面会因为替换出现其他的“\” var r = new Regex("[\\*\\.\\?\\+\\$\\^\\[\\]\\(\\)\\{\\}\\|\\/]"); var ms = r.Matches(input); var list = new List<string>(); foreach (Match item in ms) { if (list.Contains(item.Value)) continue; input = input.Replace(item.Value, "\\" + item.Value); list.Add(item.Value); } return input; } }
- ElasticsSearch——Query String
- ElasticsSearch——HighLights
- ElasticsSearch——部署环境(JDK)
- Elasticsearch Query String Query
- Query String Query【官网】
- ElasticsSearch安装
- Ravendb String.Contains() Query
- codeigniter QUERY STRING GET
- nodej-- Query String
- nginx 配置$Query String
- Hibernate—Query
- ElasticsSearch - (1)安装:
- ElasticsSearch - (2)配置:
- [ElasticsSearch] geohash (一)
- [ElasticsSearch] 排序(一)
- Query String Inspector for Flex
- Javascript Get request query string
- Form Query String Parameter Tool
- 重温Java中的接口
- MQTT介绍
- "中文编程"是解决中国程序员编程效率的一个"银弹"?
- KM算法理解
- GIS算法资料
- ElasticsSearch——Query String
- Git详解之六 Git工具
- Java设计模式——单例设计模式
- 贝叶斯网络
- 如何连接VPN
- Coderforce 602B Approximating a Constant Range(RMQ)
- 如何申请芬兰居留许可(留学)
- Git详解之七 自定义Git
- Spark-1.0.0 standalone分布式安装教程