gpt4 book ai didi

elasticsearch - 如何在Elasticsearch中使用match_phrase查询使用正则表达式搜索子对象的值字段

转载 作者:行者123 更新时间:2023-12-03 02:12:02 24 4
gpt4 key购买 nike

Elasticseach中的层次结构文档如下

"hierarchy":{
"username":"Nothing on",
"Location":"",
"Owner":"unknown",
"works": "IT"

}
是否有任何方法可以用层次结构内的任何字段搜索值,层次结构内的字段是动态的,并尝试使用正则表达式模式匹配并出错。
我们无法指定 ,例如architecture.works,hierarchy.Owner 等。因为在层次结构内的 字段是动态的,还使用了转义字符串,但它也会产生错误。
{
"from": 0,
"query": {
"multi_match": {
"query": "IT",
"type": "phrase_prefix",
"fields": [
"number",
"name",
"address",
"hierarchy.*.",
"tags"
],
}
}
}

最佳答案

If no fields are provided, the multi_match query defaults to theindex.query.default_field index settings, which in turn defaults to *.This extracts all fields in the mapping that are eligible to term queries and filters the metadata fields. All extracted fields are thencombined to build a query.


由于 hierarchy字段是动态的,因此您无法指定要查询的字段,因此查询查询的一种方法是在 field参数中不添加任何字段。
索引数据1:
{
"hierarchy": {
"username": "Nothing on",
"Location": "",
"Owner": "unknown",
"works": "IT",
"education":"btech"
}
}
索引数据2:
{
"hierarchy": {
"username": "Nothing on",
"Location": "",
"Owner": "unknown",
"works": "IT"
}
}
搜索查询:
{
"query": {
"multi_match": {
"query": "btech",
"type": "phrase_prefix"
}
}
}
搜索结果:
 "hits": [
{
"_index": "64467424",
"_type": "_doc",
"_id": "2",
"_score": 0.2876821,
"_source": {
"hierarchy": {
"username": "Nothing on",
"Location": "",
"Owner": "unknown",
"works": "IT",
"education": "btech"
}
}
}
]
编辑1:

You can use the query_string query to create a complex search thatincludes wildcard characters, searches across multiple fields, andmore. While versatile, the query is strict and returns an error if thequery string includes any invalid syntax.

{
"query": {
"query_string": {
"fields": [
"number",
"name",
"address",
"hierarchy*",
"tags"
],
"query": "btech"
}
}
}

关于elasticsearch - 如何在Elasticsearch中使用match_phrase查询使用正则表达式搜索子对象的值字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64467424/

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