通过通配符搜索elasticsearch字符串字段

问题描述 投票:0回答:1

我的elasticsearch索引有一个string类型的“message”字段。我正在尝试搜索包含消息字段部分匹配的记录。例如,如果记录包含“Hello World”,则搜索“hello”,“Hello”,“o w”等等将导致匹配。

以下是索引中的示例记录:

{
        "_index": "applicationlogs",
        "_type": "upstream",
        "_id": "d7Hj12EBs1AV7_j_56mg",
        "_score": null,
        "_source": {
          "@timestamp": "2018-02-27T09:33:16.7817021-06:00",
          "level": "Information",
          "messageTemplate": "Elasticsearch log level configured to Information",
          "message": "Elasticsearch log level configured to Information",
          "fields": {
            "SourceContext": "Rpr.Agg.Program",
            "ApplicationVersion": "1.0.0.0",
            "ServiceName": "BDF_SERVICE_SWBR2DEV-JTC01",
            "MachineName": "SWBR2DEV-JTC01",
            "Application": 8
          }
        },
        "sort": [
          1519745596781
        ]
      },

以下是镜像索引的类的相关部分:

public class ElasticsearchLogEntry
    {
        [Text(Name = "@timestamp")]
        public DateTime TimeStamp { get; set; }
        public string Level { get; set; }
        [Text]
        public string Message { get; set; }
    }

这是我到目前为止查询的相关部分,它只匹配完整的字符串:

public async Task<IEnumerable<ElasticsearchLogEntry>> GetAllLogEntries(string search, int skip, int take)
        {
            var filters = new List<Func<QueryContainerDescriptor<ElasticsearchLogEntry>, QueryContainer>>();
            if (!String.IsNullOrEmpty(search))
                filters.Add(fq => fq.Match(m => m.Field("message").Query(search)));

            var response = await client.SearchAsync<ElasticsearchLogEntry>(i => i
                .Index("applicationlogs")
                .Type("upstream")
                .Query(q => q.Bool(bq => bq.Filter(filters)))
                .Sort(s => s.Descending(so => so.TimeStamp))
                .Skip(skip)
                .Take(take));
            return response.Documents.AsEnumerable();
        }

任何想法如何让它正常工作?

c# elasticsearch nest elasticsearch-5 elasticsearch-net
1个回答
0
投票

我以为我只是得到0结果,但事实证明我实际上得到了一个错误:

{ServerError:400Type:parsing_exception原因:“[match]查询不支持[type]”}

我认为这是因为我在我的查询中设置了一个Type,但是即使在删除它之后我仍然会收到错误。我想这是因为我在使用NEST / ElasticSearch.Net 5.x nuget包时连接到亚马逊上的ES 6实例。见this

不幸的是,我使用5.x nuget软件包的全部原因是因为6对我或我团队中的其他开发人员不起作用。 api调用总是给this error

UnexpectedElasticsearchClientException:找不到方法:'Elasticsearch.Net.PostData`1 Elasticsearch.Net.RequestData.get_PostData()'。

所以这让我陷入了困境......

编辑:他们发布了支持6.x的ES AWS nuget包的更新,因此我能够升级所有内容并克服这些错误。

© www.soinside.com 2019 - 2024. All rights reserved.