1

Here is my mapping

[ElasticsearchType(Name = "Topic")]
public class Topic
{
    [Number(NumberType.Integer, Coerce = true)]
    public EnumStatus Status { get; set; }

    [Nested]
    public List<KeywordValue> KeywordValues { get; set; }

}

[ElasticsearchType(Name = "KeywordValue")]
public class KeywordValue
{
    [Keyword]
    public string KeywordId { get; set; }

}

I have 10 documents of type Topic in the index, each KeywordValues property/field of the type List<KeywordValue> contains 5 KeywordValue (5 elements in the list).

9 documents have status "Enabled";

I'm trying to count the total number of elements in each nested KeywordValues field. The result returned is 9 but I would like to get 45 (9*5)

I'm doing this:

var response = Topic.CurrentConnection.Search<Topic>(s => s
                .Size(0)
                .Aggregations(fa => fa
                    .Filter("filtered_aggs", f => f
                        .Filter(fd => fd.Term(t => t.Status, Topic.EnumStatus.Enabled))
                        .Aggregations(ta => ta
                                .Nested("kv", n=>n.Path(p => p.KeywordValues)
                                    .Aggregations(aa => aa
                                        .ValueCount("vc", v => v.Field(vf => vf.KeywordValues.First().KeywordId))))
                            )
                        )
                    )
            );


        if (response.IsValid)
        {
            var agg = response.Aggregations.Nested("filtered_aggs");
            var n = agg.Nested("kv");
            var z = n.ValueCount("vc");
            result.Object = z.Value;
        }

Raw query equivalent:

# Request:
{
  "size": 0,
  "aggs": {
    "filtered_aggs": {
      "filter": {
        "term": {
          "Status": {
            "value": 0
          }
        }
      },
      "aggs": {
        "kv": {
          "nested": {
            "path": "KeywordValues"
          },
          "aggs": {
            "vc": {
              "value_count": {
                "field": "KeywordValues.KeywordId"
              }
            }
          }
        }
      }
    }
  }
}
# Response:
{
  "took" : 80,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 10,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "filter#filtered_aggs" : {
      "doc_count" : 9,
      "nested#kv" : {
        "doc_count" : 9,
        "value_count#vc" : {
          "value" : 9
        }
      }
    }
  }
}

Any idea? Thanks a lot.


NPM Insall error (Angular 6)

I have an Angular 6 project and when I try to execute it, it throws the following error:

Could not find module "@angular-devkit/build-angular" from "C:\\Users\\fernando.cavalcante\\Desktop\\Fernando_Backup\\VisualStudio2017\\Projects\\GerenciadorDiretorioAPI\\Presentattion".
Error: Could not find module "@angular-devkit/build-angular" from ...

I tried to update the packages but when I run npm install command, cmd throws the following message:

npm WARN tar ENOENT: no such file or directory, open 'C:\Users\me\Desktop\Folder1\Projects\My.Project\Developing\0 - Presentation\My.Project\node_modules\.staging\es5-ext-b75d419b\test\reg-exp\#\sticky\is-implemented.js'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: 403 Forbidden: fsevents@https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz

npm ERR! code EINTEGRITY
npm ERR! sha1-PFtv1/beCRQmkCfwPAlGdY92c6Q= integrity checksum failed when using sha1: wanted sha1-PFtv1/beCRQmkCfwPAlGdY92c6Q= but got sha1-pMeCeEFUzmIX1LXY6ZTg7bwjcDY=. (4472399 bytes)

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\me\AppData\Roaming\npm-cache\_logs\2018-05-18T13_11_28_030Z-debug.log

I searched some solutions here, here, here and here, tried to reinstall Node, reinstall Angular and even searched in some unresolved questions but nothing worked for me.

I also tried this solution and run npm clean cache -f but didn't work.

I don't know how to proceed.

I'm using Angular CLI: 6.0.1 and Node: 8.11.2

4

1 回答 1

0

这是一个工作示例

private static void Main()
{
    var defaultIndex = "topics";
    var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

    var settings = new ConnectionSettings(pool)
        .DefaultIndex(defaultIndex);

    var client = new ElasticClient(settings);

    if (client.IndexExists(defaultIndex).Exists)
        client.DeleteIndex(defaultIndex);

    client.CreateIndex(defaultIndex, c => c
        .Mappings(m => m
            .Map<Topic>(mm => mm
                .AutoMap()
            )
        )
    );

    var documents = Enumerable.Range(1, 10)
        .Select(i => new Topic
        {
            Status = i == 1 ? EnumStatus.Disabled : EnumStatus.Enabled,
            KeywordValues = Enumerable.Range(1, 5)
                .Select(j => new KeywordValue
                {
                    KeywordId = $"keyword {i} {j}"
                }).ToList()
        });

    client.Bulk(b => b
        .IndexMany(documents, (d, document) => d
            .Document(document)
        )
        .Refresh(Refresh.WaitFor)
    );

    client.Search<Topic>(s => s
        .Size(0)
        .Query(q => +q
            .Term(t => t.Status, (int)EnumStatus.Enabled)
        )
        .Aggregations(ta => ta
            .Nested("kv", n => n.Path(p => p.KeywordValues)
                .Aggregations(aa => aa
                    .ValueCount("vc", v => v.Field(vf => vf.KeywordValues.First().KeywordId))))
        )
    );
}

[ElasticsearchType(Name = "Topic")]
public class Topic
{
    [Number(NumberType.Integer, Coerce = true)]
    public EnumStatus Status { get; set; }

    [Nested]
    public List<KeywordValue> KeywordValues { get; set; }

}

[ElasticsearchType(Name = "KeywordValue")]
public class KeywordValue
{
    [Keyword]
    public string KeywordId { get; set; }
}

public enum EnumStatus
{
    Enabled,

    Disabled
}

对搜索请求的响应是

{
  "took" : 9,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 9,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "nested#kv" : {
      "doc_count" : 45,
      "value_count#vc" : {
        "value" : 45
      }
    }
  }
}
于 2018-05-23T06:56:19.253 回答