在elasticsearch中组合字段(combine fields in elasticsearch)
假设我在SQL中有一个表,我将两个字段合并为一个
A | B -----|-------- => select A+' '+ B as Name => BMW X-Series BMW | 3-Series BMW | X3
我把它转储到临时表中,然后在临时表上进行通配符搜索,返回带有count的结果
select Name,count(Name) as frequency from Table where Name like '%3%' group by Name Name Frequency ------------------ BMW 3-Series | 1 BMW X3 | 1
现在我如何实现同样的弹性搜索,因为A和B是单独的字段。
我试过这个:
{ "query":{ "query_string":{ "fields":["A","B"], "query":"3" } }, "aggs": { "count": { "terms": { "field": "A" }, "aggs": { "count": { "terms": { "field": "B" } } } } } }
如何在查询上添加正则表达式
Suppose I have a table in SQL where I combine two fields as one
A | B -----|-------- => select A+' '+ B as Name => BMW X-Series BMW | 3-Series BMW | X3
I dump it into a temp table and I do a wildcard search on the temp table which returns the result with count
select Name,count(Name) as frequency from Table where Name like '%3%' group by Name Name Frequency ------------------ BMW 3-Series | 1 BMW X3 | 1
Now how do I achieve the same is elasticsearch given that A and B are seperate fields.
I tried this:
{ "query":{ "query_string":{ "fields":["A","B"], "query":"3" } }, "aggs": { "count": { "terms": { "field": "A" }, "aggs": { "count": { "terms": { "field": "B" } } } } } }
How do I add regular expression on the query
原文:https://stackoverflow.com/questions/37364155
更新时间:2023-02-14 17:02
最满意答案
单程:
"rxrx".gsub(/(x)/) { |s| s.upcase }
我建议这个而不仅仅是正常替换(
gsub("x", "X")
)的唯一原因是因为如果有多个字符想要大写,它会很好用:"rxbrx".gsub(/([xb])/) { |s| s.upcase }
One way:
"rxrx".gsub(/(x)/) { |s| s.upcase }
The only reason I suggest this instead of just normal substitution (
gsub("x", "X")
) is because it'd work well if there were more than one character you wanted to make uppercase:"rxbrx".gsub(/([xb])/) { |s| s.upcase }
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
我可以使用awk将所有小写字母转换为大写字母吗?(Can I use awk to convert all the lower-case letters into upper-case?)[2023-10-15]
尝试这个: awk '{ print toupper($0) }' <<< "your string" 使用文件: awk '{ print toupper($0) }' yourfile.txt Try this: awk '{ print toupper($0) }' <<< "your string" Using a file: awk '{ print toupper($0) }' yourfile.txt -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
在尝试提出自己的方法(包括以下参考)时,我意识到有一些非常讨厌的角色。 更好的只是使用Facet中提供的方法,这是最好的最好的Ruby库evar: require 'facets/string/titlecase' class String def titleize split(/(\W)/).map(&:capitalize).join end end require 'test/unit' class TestStringTitlecaseAndTitleize < Test::Un ...
-
如果您需要一个正则表达式,请尝试: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$ 一个简短的解释: ^ // the start of the string (?=.*[a-z]) // use positive look ahead to see if at least one lower case letter exists (?=.*[A-Z]) // use positive loo ...
-
Ruby有几种改变字符串的方法。 要转换为小写,请使用小写字母: "hello James!".downcase #=> "hello james!" 同样,大写字母大写每个字母和capitalize大写字符串的第一个字母,但其余部分: "hello James!".upcase #=> "HELLO JAMES!" "hello James!".capitalize #=> "Hello james!" "hello James!".titleize #=> "Hello Jam ...
-
var lowerCaseName = "Your Name".toLowerCase(); var lowerCaseName = "Your Name".toLowerCase();
-
在Haskell中将大写字母转换为小写字母和计数字符串(Convert uppercase letters to lower case and count strings in Haskell)[2022-11-03]
在解决方案中有一些优化空间。 首先 ,函数letter_count在O(n ^ 2)时间运行:当[(c, countL sc) | c <- s] 对于n个字母串的每个字符计算[(c, countL sc) | c <- s] ,通过countL执行O(n)查找。 这不是最佳的时间复杂性 - 数字可以更快地完成。 如果您只想考虑字母[a,...,z],则可以使用Data.Array数组(在注释中提及的@dfeuer中的O(n log k)使用Data.IntMap.Strict时间如果你想坚持列表 - 这会 ... -
BASH同时将大写字母转换为小写字母,反之亦然(BASH convert uppercase to lower case and vice versa at same time)[2023-07-12]
您可以轻松地将两条线组合在一起: $ tr '[:upper:][:lower:]' '[:lower:][:upper:]' <<< "hEllo" HeLLO You can readily combine your two lines: $ tr '[:upper:][:lower:]' '[:lower:][:upper:]' <<< "hEllo" HeLLO -
单程: "rxrx".gsub(/(x)/) { |s| s.upcase } 我建议这个而不仅仅是正常替换( gsub("x", "X") )的唯一原因是因为如果有多个字符想要大写,它会很好用: "rxbrx".gsub(/([xb])/) { |s| s.upcase } One way: "rxrx".gsub(/(x)/) { |s| s.upcase } The only reason I suggest this instead of just normal substitution (g ...