社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

briarheart

briarheart 最近创建的主题
briarheart 最近回复了
7 年前
回复了 briarheart 创建的主题 » 根据值列表获取ElasticSearch匹配

当然,不应该在循环中使用通配符查询。此解决方案最终将显示出较差的性能。

自从 roles 字段是常规文本字段ElasticSearch将值“role1;role2;role3”拆分为单个标记“role1”、“role2”和“role3”。相同的操作应用于搜索查询。您可以使用查询字符串“role3;role4;role5”进行简单匹配查询,并因为“role3”令牌匹配而被击中。

你也可以索引 角色 字段作为字符串数组和相同的匹配查询仍然有效。

7 年前
回复了 briarheart 创建的主题 » 使用ElasticSearch返回到另一个空字段

你可以用 should exists 条款。假设您有以下两个文档:

// Document 1
{
  "body": "quick brown fox",
  "body_edited": null
}

// Document 2
{
  "body": "quick brown fox",
  "body_edited": "jumps over the lazy dog"
}

下面是搜索术语“brown fox”的示例:

"query": {
  "bool": {
    "should": [
      {
        "match": {
          "body_edited": "brown fox"
        }
      },
      {
        "bool": {
          "must": {
            "match": {
              "body": "brown fox"
            }
          },
          "must_not": {
            "exists": {
              "field": "body_edited"
            }
          }
        }
      }
    ]
  }
}

尽管事实上 body 文档2中的字段也符合我们的搜索条件。

7 年前
回复了 briarheart 创建的主题 » ElasticSearch放弃包含查询超集的文档

如果您不关心区分大小写,只需使用 term 查询:

{
  "query": {
    "term": {
      "cities.keyword": "Paris Zurich"
    }
  }
}

它将只匹配字段的精确值。

另一方面,您可以创建自定义分析器,它仍然存储字段的确切值(就像 keyword )有一个例外:存储的值将被转换为小写,这样您就可以找到 Paris Zurich 以及 paris Zurich . 示例如下:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "lowercase_analyzer": {
          "type": "custom",
          "tokenizer": "keyword",
          "char_filter": [],
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "cities": {
          "type": "text",
          "fields": {
            "lowercased": {
              "type": "text",
              "analyzer": "lowercase_analyzer"
            }
          }
        }
      }
    }
  }
}

{
  "query": {
    "term": {
      "cities.lowercased": "paris zurich" // Query string should also be in lowercase
    }
  }
}