elasticsearch中的logstash查询嵌套数组

whhtz7ly  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(0)|浏览(309)

我有一个对象,我想索引到elasticsearch索引中。对象中的一些字段中有一个嵌套的json对象数组。例如:

  1. "history":[
  2. {"color":"w","from":"g2","to":"g4","flags":"b","piece":"p","san":"g4","ts":{"$numberLong":"1586861525811"}},
  3. {"color":"b","from":"e7","to":"e5","flags":"b","piece":"p","san":"e5","ts":{"$numberLong":"1586861527710"}},
  4. {"color":"w","from":"f2","to":"f4","flags":"b","piece":"p","san":"f4","ts":{"$numberLong":"1586861531620"}},
  5. {"color":"b","from":"d8","to":"h4","flags":"n","piece":"q","san":"Qh4#","ts":{"$numberLong":"1586861533363"}}
  6. ],

我用于此字段的Map是:

  1. {
  2. "mappings": {
  3. "properties": {
  4. "history" : {
  5. "type" : "nested",
  6. "properties": {
  7. "color": {"type" : "keyword"},
  8. "from" : {"type" : "keyword"},
  9. "to" : {"type" : "keyword"},
  10. "flags" : {"type" : "keyword"},
  11. "san" : {"type" : "keyword"},
  12. "ts" : {
  13. "type" : "nested"
  14. }
  15. }
  16. }
  17. }
  18. }
  19. }

我面临的问题是,当我将对象放入索引时,如果history字段中存储了多个对象,那么Map就不起作用。在kibana中,历史字段存储如下:

  1. {
  2. "color": "w",
  3. "from": "g2",
  4. "to": "g4",
  5. "flags": "b",
  6. "piece": "p",
  7. "san": "g4",
  8. "ts": {
  9. "$numberLong": "1586861525811"
  10. }
  11. },
  12. {
  13. "color": "b",
  14. "from": "e7",
  15. "to": "e5",
  16. "flags": "b",
  17. "piece": "p",
  18. "san": "e5",
  19. "ts": {
  20. "$numberLong": "1586861527710"
  21. }
  22. },
  23. {
  24. "color": "w",
  25. "from": "f2",
  26. "to": "f4",
  27. "flags": "b",
  28. "piece": "p",
  29. "san": "f4",
  30. "ts": {
  31. "$numberLong": "1586861531620"
  32. }
  33. },
  34. {
  35. "color": "b",
  36. "from": "d8",
  37. "to": "h4",
  38. "flags": "n",
  39. "piece": "q",
  40. "san": "Qh4#",
  41. "ts": {
  42. "$numberLong": "1586861533363"
  43. }
  44. }

我在Map中指定的不同嵌套字段没有填充。
我的Map有问题吗?如果history字段只有一个对象(例如:

  1. "history":
  2. {"color":"w","from":"g2","to":"g4","flags":"b","piece":"p","san":"g4","ts":{"$numberLong":"1586861525811"}}

但对于多个对象,它无法正确Map。有什么问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题