这应该是显而易见的,但事实并非如此.以下两个仅匹配第二个短语(在本例中为"Cape Basin")
"query": {
"match_phrase": {
"contents": {
"query": "St Peter Fm",
"query": "Cape Basin"
}
}
}
"query": {
"match_phrase": {
"contents": {
"query": ["St Peter Fm", "Cape Basin"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
而以下呱呱叫错了
"query": {
"match_phrase": {
"contents": {
"query": "St Peter Fm"
},
"contents": {
"query": "Cape Basin"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想匹配包含的所有文件都 要么 完全相同短语输入.
更新:请参阅上面的更新
我正在使用 ElasticSearch,我正在尝试实现 match_phrase/string + 模糊性,但似乎这是不可能的(网上没有那么多例子,文档中没有这样的情况)。
我需要什么:短语/字符串匹配+模糊+基于字段的每个值的倾斜。
到目前为止我已经尝试过的(而且我仍然没有我需要的解决方案):
query_string - 它包含模糊性和倾斜度。但是,它通过一个文档的所有字段值收集一个字符串。
match_phrase - 它包含了slop,但没有模糊性。好处是 - 它至少在字段的一个值中查找短语匹配,而不是通过文档字段的所有值收集字符串。
我需要的:
有人有 ElasticSearch 上的短语匹配(包括模糊性)方面的经验吗?
提前致谢。
我是弹性搜索的新手,因此我在努力寻找适合我们数据的最佳查询方面有些困难。
想象一下,我想匹配以下单词“ Handelsstandens Boldklub”。
当前,我正在使用以下查询:
{
query: {
bool: {
should: [
{
match: {
name: {
query: query, slop: 5, type: "phrase_prefix"
}
}
},
{
match: {
name: {
query: query,
fuzziness: "AUTO",
operator: "and"
}
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
当前,如果我正在搜索“手”,它将列出该单词,但是如果我搜索“手”,则该单词将不再像打字时一样列出。但是,如果我以“ Handlesstandens”结尾,则会再次列出该列表,因为模糊不清会引起拼写错误,但仅当我键入整个单词时才如此。
是否可以同时进行短语前缀和模糊性?因此,在上述情况下,如果我在路上打错字,它还会列出单词吗?
因此,在这种情况下,如果我搜索“ Handle”,它将仍然与单词“ Handelsstandens Boldklub”匹配。
或者,还有哪些其他解决方法可以实现上述体验?我喜欢phrase_prefix匹配,因为它还支持草率匹配(因此,我可以搜索“ Boldklub han”,它将列出结果)
还是可以通过使用完成提示器来实现上述目的?
我正在尝试在弹性搜索中实现精确匹配搜索.但我没有得到所需的结果.这是解释我面临的问题和我尝试过的事情的代码.
doc1 = {"sentence": "Today is a sunny day."}
doc2 = {"sentence": " Today is a sunny day but tomorrow it might rain"}
doc3 = {"sentence": "I know I am awesome"}
doc4 = {"sentence": "The taste of your dish is awesome"}
doc5 = {"sentence": "The taste of banana shake is good"}
# Indexing the above docs
es.index(index="english",doc_type="sentences",id=1,body=doc1)
es.index(index="english",doc_type="sentences",id=2,body=doc2)
es.index(index="english",doc_type="sentences",id=3,body=doc3)
es.index(index="english",doc_type="sentences",id=4,body=doc4)
es.index(index="english",doc_type="sentences",id=5,body=doc5)
Run Code Online (Sandbox Code Playgroud)
查询1
res = es.search(index="english",body={"from":0,"size":5,
"query":
{"match_phrase":
{"sentence":{"query":"Today is a sunny day"}
}},
"explain":False})
Run Code Online (Sandbox Code Playgroud)
查询2
res = es.search(index="english",body={"from":0,"size":5,
"query":{
"bool":{ …
Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用 Elasticsearch,版本 7.5.1。
我想查询以特定单词片段开头的结果。例如tho * 应该返回包含以下内容的数据:
思想,汤姆森,那些,等等。
我试过 -
[{'regexp':{'f1':'tho.*'}},{'regexp':{'f2':'tho.*'}}]
Run Code Online (Sandbox Code Playgroud)
[{'wildcard':{'f1':'tho*'}},{'wildcard':{'f2':'tho*'}}]
Run Code Online (Sandbox Code Playgroud)
[{'prefix':{'f1':'tho'}},{'prefix':{'f2':'tho'}}]
Run Code Online (Sandbox Code Playgroud)
'multi_match': {'query': 'tho', 'fields':[f1,f2,f3], 'type':phrase}
# also tried with type phrase_prefix
Run Code Online (Sandbox Code Playgroud)
所有这些都返回正确的结果,但它们也都返回单词method。
同样,cat * 返回了“ communication”这个词。
我做错了什么?这与分析器有关吗?
'f1': {
'full_name': 'f1',
'mapping': {
'f1': {
'type': 'text',
'analyzer': 'some_analyzer',
'index_phrases': true
}
}
},
Run Code Online (Sandbox Code Playgroud)