【问题标题】:Proper use of filters in ElastichSearch在 ElasticSearch 中正确使用过滤器
【发布时间】:2014-12-26 08:42:23
【问题描述】:

我在 Elasticsearch 中输入这个文档:

    {
    "id":"b35d0a97-5f00-41a0-a321-30d387a65692",
    "products": ["http://...."],
    "parameters": {
        "Gender": ["Women"],
        "Waistline": ["Empire"],
        "Is_customized": ["Yes"],
        "Dresses length": ["Knee-length"],
        "Silhouette": ["Sheath"],
        "Neckline": ["Square collar"],
        "Sleeve length": ["Short"],
        "Style": ["Casual"],
        "Material": ["Acetate","Spandex","Viscose"]
    },
    "globalCategory": "99a74e52-d122-4177-b77c-12427d84f365"
}

我正在尝试使用过滤器找到它:

{
    "query": {
        "filtered": {

            "filter": {

                    "term": 
                    {
                        "globalCategory": "99a74e52-d122-4177-b77c-12427d84f365"
                    }


            }
        }
    }
}

但是 Elasticsearch 什么也找不到!请告诉我我的错误是什么?

【问题讨论】:

  • 你能重现你所做的整个操作集吗?从创建索引(如果有)、创建映射(如果有)、索引文档到最后发出搜索。
  • 请您发布您的映射吗?
  • 在索引中添加数据,我使用了 C# 和库 NEST。映射是从 C# 的类中自动生成的。 GlobalCategory 字段为 Guid 类型,映射时转换为“字符串”。
  • 由于JSON格式的'parameters'映射中的值种类繁多,大小约为3兆字节。

标签: search filter elasticsearch full-text-search


【解决方案1】:

看到这里,您使用了默认映射。字段 globalCategory than 成为使用标准分析器分析的字符串。因此,您的索引中有一些术语:

99a74e52
d122
4177
b77c
12427d84f365

在这种情况下,我最好的选择是添加一个映射并使字段 globalCategory not_analyzed,这样该字段被用作一个术语并且过滤器将完成它的工作。

【讨论】:

  • 我使用了属性not_analyzed字段globalCategory:[ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]public Guid GlobalCategory { get; set; } 但是没有给出任何结果...
  • 您可以将当前映射添加到您的问题中吗?你可以使用server:port/your_index/_mapping
  • { "mappings": { "productclustermodeles": { "properties": { "globalCategory": { "type": "string" }, "id": { "type": "string" }, "products": { "type": "string" } } } } }
  • 我发现了一个错误!什么会赢得 POCO 映射需要拨打电话:client.CreateIndex ("products_index", s => s .AddMapping <ProductClusterModelEs> (m => m.MapFromAttributes ()));我一做就是:"globalCategory": {"type": "string", "index": "not_analyzed"}。过滤器开始按我的需要工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-18
相关资源
最近更新 更多