query

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

query

WIP: query TXN2 data by account, model and index pattern. Save queries and execute saved queries.

Examples

Start server:

go run ./cmd/query.go --tokenKey=$TOKEN_KEY --esServer=http://elasticsearch:9200

Run / Test a query:

curl -X POST \
  http://localhost:8080/run/xorg \
  -H 'Authorization: Bearer $TOKEN' \
  -d '{
    "machine_name": "all_los_angeles_parking_citations",
    "display_name": "All Los Angeles Parking Citations",
    "description_brief": "Gets all Los Angeles parking citation records available.",
    "description": "This is a dataset hosted by the city of Los Angeles. The organization has an open data platform found [here](https://data.lacity.org/)",
    "query_class": "table",
    "model": "los_angeles_parking_citations",
    "idx_pattern": "-testset",
    "query": {
	  "query": {
	    "match_all": {}
	  }
	}
}'

Upsert a query:

curl -X POST \
  http://localhost:8080/upsert/xorg \
  -H 'Authorization: Bearer $TOKEN' \
  -d '{
    "machine_name": "all_los_angeles_parking_citations",
    "display_name": "All Los Angeles Parking Citations",
    "description_brief": "Gets all Los Angeles parking citation records available",
    "description": "This is a dataset hosted by the city of Los Angeles. The organization has an open data platform found [here](https://data.lacity.org/)",
    "query_class": "table",
    "model": "los_angeles_parking_citations",
    "idx_pattern": "-testset",
    "query": {
	  "query": {
	    "match_all": {}
	  }
	}
}'

Search for queries:

curl -X POST \
  http://localhost:8080/search/xorg \
  -H 'Authorization: Bearer $TOKEN' \
  -d '{
  "size": 10,
  "query": {
    "match_all": {}
  }
}'

Get a query:

curl -X GET \
  http://localhost:8080/get/xorg/all_los_angeles_parking_citations \
  -H 'Authorization: Bearer $TOKEN'

Documentation

Overview

Copyright 2019 txn2 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const IdxQuery = "queries"

Variables

This section is empty.

Functions

func GetQueryTemplateMapping

func GetQueryTemplateMapping() es.IndexTemplate

GetModelsTemplateMapping

Types

type Api

type Api struct {
	*Config
}

Api

func NewApi

func NewApi(cfg *Config) (*Api, error)

NewApi

func (*Api) ExecuteQuery

func (a *Api) ExecuteQuery(account string, query Query) (int, *es.Obj, error)

ExecuteQuery

func (*Api) ExecuteQueryHandler

func (a *Api) ExecuteQueryHandler(c *gin.Context)

ExecuteQueryHandler

func (*Api) GetQuery

func (a *Api) GetQuery(account string, id string) (int, *Result, error)

GetModel

func (*Api) GetQueryHandler

func (a *Api) GetQueryHandler(c *gin.Context)

GetQueryHandler

func (*Api) RunQueryHandler

func (a *Api) RunQueryHandler(c *gin.Context)

ExecuteQueryHandler

func (*Api) SearchQueries

func (a *Api) SearchQueries(account string, searchObj *es.Obj) (int, SearchResults, error)

SearchModels

func (*Api) SearchQueryHandler

func (a *Api) SearchQueryHandler(c *gin.Context)

SearchQueryHandler

func (*Api) UpsertQuery

func (a *Api) UpsertQuery(account string, query *Query) (int, es.Result, error)

UpsertQuery

func (*Api) UpsertQueryHandler

func (a *Api) UpsertQueryHandler(c *gin.Context)

UpsertQueryHandler

type Config

type Config struct {
	Logger     *zap.Logger
	HttpClient *micro.Client

	// used for communication with Elasticsearch
	// if nil, HttpClient will be used.
	Elastic       *es.Client
	ElasticServer string
}

Config

type Query

type Query struct {
	// a lowercase under score delimited uniq id
	MachineName string `json:"machine_name" mapstructure:"machine_name"`

	// short human readable display name
	DisplayName string `json:"display_name" mapstructure:"display_name"`

	// a single sentence description
	BriefDescription string `json:"description_brief" mapstructure:"description_brief"`

	// full documentation in markdown
	Description string `json:"description" mapstructure:"description"`

	// named parsers
	Parsers []string `json:"parsers" mapstructure:"parsers"`

	// belongs to a class of queries
	QueryClass string `json:"query_class" mapstructure:"query_class"`

	// used for grouping queries
	Group string `json:"group" mapstructure:"group"`

	// used for grouping queries
	Model string `json:"model" mapstructure:"model"`

	// pattern default "-*" eg. "-someset", "-ts-2019*"
	IdxPattern string `json:"idx_pattern" mapstructure:"idx_pattern"`

	// query object
	Query *es.Obj `json:"query,omitempty" mapstructure:"query"`

	// query json
	QueryJson string `json:"query_json,omitempty" mapstructure:"query_json"`

	// describes the query output
	ResultFields []tm.Model `json:"fields" mapstructure:"fields"`
}

Query

type Result

type Result struct {
	es.Result
	Source Query `json:"_source"`
}

Result returned from Elastic

type SearchResults

type SearchResults struct {
	es.SearchResults
	Hits struct {
		Total    int      `json:"total"`
		MaxScore float64  `json:"max_score"`
		Hits     []Result `json:"hits"`
	} `json:"hits"`
}

ModelSearchResults

type SearchResultsAck

type SearchResultsAck struct {
	ack.Ack
	Payload SearchResults `json:"payload"`
}

AccountSearchResultsAck

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL