Элемент запроса во вложенной динамике c уровень json - PullRequest
0 голосов
/ 20 февраля 2020

Образец json данных

{
    type: 'EVENT_TYPE',
    name: 'Australian Rules',
    id: '61420',
    children: [
      {
        type: 'EVENT',
        name: 'AFL',
        id: '28159788',
        countryCode: 'AU',
        children: [
          {
            type: 'EVENT',
            name: 'Adelaide v Sydney',
            id: '29558280',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168080433',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-21T05:35:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168080418',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-03-21T05:35:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'Essendon v Fremantle',
            id: '29558279',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168080217',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-21T02:45:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168080202',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-03-21T02:45:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'GWS v Geelong',
            id: '29558281',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168080865',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-21T08:25:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168080850',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-03-21T08:25:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'Gold Coast v Port Adelaide',
            id: '29558282',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168080649',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-21T08:25:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168080634',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-03-21T08:25:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'Hawthorn v Brisbane',
            id: '29558284',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168081297',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-22T04:20:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168081282',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-03-22T04:20:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'North Melbourne v St Kilda',
            id: '29558283',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168081081',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-22T02:10:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168081066',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-03-22T02:10:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'Richmond v Carlton',
            id: '29558277',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168079783',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-19T08:25:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168079768',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-03-19T08:25:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'West Coast v Melbourne',
            id: '29558285',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168081513',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-22T06:20:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168081498',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-03-22T06:20:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'Western Bulldogs v Collingwood',
            id: '29558278',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168080000',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-20T08:50:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168079985',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-03-20T08:50:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'MARKET',
            name: 'Coleman Medal',
            id: '1.165888926',
            exchangeId: '1',
            marketType: 'UNUSED',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 1,
          },
          {
            type: 'MARKET',
            name: 'Grand Final Quinella',
            id: '1.168361297',
            exchangeId: '1',
            marketType: 'UNUSED',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 1,
          },
          {
            type: 'MARKET',
            name: 'Least Season Wins',
            id: '1.168081746',
            exchangeId: '1',
            marketType: 'UNUSED',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 1,
          },
          {
            type: 'MARKET',
            name: 'Minor Premiers',
            id: '1.165888922',
            exchangeId: '1',
            marketType: 'UNUSED',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 1,
          },
          {
            type: 'MARKET',
            name: 'Premiers 2020',
            id: '1.162996979',
            exchangeId: '1',
            marketType: 'WINNER',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 1,
          },
          {
            type: 'MARKET',
            name: 'Rising Star',
            id: '1.165888927',
            exchangeId: '1',
            marketType: 'UNUSED',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 1,
          },
          {
            type: 'MARKET',
            name: 'Season Points Handicap',
            id: '1.168706732',
            exchangeId: '1',
            marketType: 'UNUSED',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 1,
          },
          {
            type: 'MARKET',
            name: 'To Reach Grand Final',
            id: '1.165888925',
            exchangeId: '1',
            marketType: 'TO_REACH_FINAL',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 2,
          },
          {
            type: 'MARKET',
            name: 'Top 4',
            id: '1.164816007',
            exchangeId: '1',
            marketType: 'TOP_N_FINISH',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 4,
          },
          {
            type: 'MARKET',
            name: 'Top 8',
            id: '1.164816033',
            exchangeId: '1',
            marketType: 'TOP_N_FINISH',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 8,
          },
          {
            type: 'MARKET',
            name: 'Top Non Vic Team',
            id: '1.168377552',
            exchangeId: '1',
            marketType: 'UNDIFFERENTIATED',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 1,
          },
          {
            type: 'MARKET',
            name: 'Top Victorian Team',
            id: '1.168376754',
            exchangeId: '1',
            marketType: 'UNDIFFERENTIATED',
            marketStartTime: '2020-03-19T08:25:00.000Z',
            numberOfWinners: 1,
          },
        ],
      },
      {
        type: 'EVENT',
        name: 'Brownlow Medal 2020',
        id: '29490678',
        countryCode: 'AU',
        children: [
          {
            type: 'MARKET',
            name: 'Winner',
            id: '1.162811621',
            exchangeId: '1',
            marketType: 'WINNER',
            marketStartTime: '2020-03-26T08:20:00.000Z',
            numberOfWinners: 1,
          },
        ],
      },
      {
        type: 'EVENT',
        name: "Women's AFL",
        id: '28113600',
        countryCode: 'AU',
        children: [
          {
            type: 'EVENT',
            name: 'Fremantle (W) v Collingwood (W)',
            id: '29706991',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168930183',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-02-22T08:10:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168930182',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-02-22T08:10:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'GWS (W) v West Coast (W)',
            id: '29706992',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168930549',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-02-23T02:10:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168930548',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-02-23T02:10:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'Geelong (W) v Adelaide (W)',
            id: '29706994',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168930305',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-02-23T06:10:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168930304',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-02-23T06:10:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'Gold Coast (W) v Brisbane (W)',
            id: '29706990',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168930427',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-02-22T06:10:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168930426',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-02-22T06:10:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'Richmond (W) v North Melbourne (W)',
            id: '29706993',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168930671',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-02-23T04:10:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168930670',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-02-23T04:10:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'St Kilda (W) v Melbourne (W)',
            id: '29706967',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168930793',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-02-21T08:10:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168930792',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-02-21T08:10:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'EVENT',
            name: 'Western Bulldogs (W) v Carlton (W)',
            id: '29706988',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168930915',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-02-22T04:10:00.000Z',
                numberOfWinners: '',
              },
              {
                type: 'MARKET',
                name: 'Match Odds',
                id: '1.168930914',
                exchangeId: '1',
                marketType: 'MATCH_ODDS',
                marketStartTime: '2020-02-22T04:10:00.000Z',
                numberOfWinners: 1,
              },
            ],
          },
          {
            type: 'MARKET',
            name: 'Premiers 2020',
            id: '1.167092010',
            exchangeId: '1',
            marketType: 'WINNER',
            marketStartTime: '2020-04-18T04:10:00.000Z',
            numberOfWinners: 1,
          },
        ],
      },
    ],
  }

Я хочу получить со всеми объектами верхнего уровня

Для поиска элемента "marketStartTime: '2020-03-21T02: 45: 00.000 Z '", который находится внутри имени:' Essendon v Fremantle '

{
  type: 'MARKET',
  name: 'Match Odds',
  id: '1.168080202',
  exchangeId: '1',
  marketType: 'MATCH_ODDS',
  marketStartTime: '2020-03-21T02:45:00.000Z',
  numberOfWinners: 1,
},
ER:
{
    type: 'EVENT_TYPE',
    name: 'Australian Rules',
    id: '61420',
    children: [
      {
        type: 'EVENT',
        name: 'AFL',
        id: '28159788',
        countryCode: 'AU',
        children:[{type: 'EVENT',
            name: 'Essendon v Fremantle',
            id: '29558279',
            countryCode: 'AU',
            children: [
              {
                type: 'MARKET',
                name: 'Handicap',
                id: '1.168080217',
                exchangeId: '1',
                marketType: 'HANDICAP',
                marketStartTime: '2020-03-21T02:45:00.000Z',
                numberOfWinners: '',
              }
         ]}]}]} 

Я пробовал несколько вещей

  1. Используя Elasti c search, nested запрос и inner_hits для получения данных, он прекрасно работает, если уровень вложенности определен, но он динамический c, следовательно, не может использоваться надежно.

  2. Попытка сгладить структурировать в одну строку и искать / запрашивать ... не кажется хорошим подходом, так как придется искать во всех полях совпадающее значение.

  3. Несколько других подходов для сглаживания данных в несколько строк, но я пытаюсь избежать рефакторинга данных через любой язык программирования с помощью циклов.

Ищите что-то с плагином для анализа данных в нескольких строках и подключения к базе данных или эластичного поиска, где api запрос может быть достиг

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...