Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

Build endpoints to access API metadata #57

Closed
arowla opened this issue May 2, 2014 · 10 comments
Closed

Build endpoints to access API metadata #57

arowla opened this issue May 2, 2014 · 10 comments
Assignees
Milestone

Comments

@arowla
Copy link
Contributor

arowla commented May 2, 2014

Requested fields to get unique values for are:

  • data_source
  • notice_type

Unique notice_types can be gotten via this aggregation:

  "aggs": { "notice_types": { "terms": {
    "field": "notice_type",
    "size": 10
  }  }  }
@arowla
Copy link
Contributor Author

arowla commented May 16, 2014

To this I'd like to add date aggregation, to show populated dates or ranges for the data that we have. Could be a separate endpoint or parameter, but the work should be similar to get here.

@arowla arowla added this to the Elasticsearch Ready for Release milestone May 16, 2014
@adelevie
Copy link
Contributor

Should the data_sources be hardcoded into the express route, or is there a (preferred) dynamic way to do this?

@arowla
Copy link
Contributor Author

arowla commented Jul 30, 2014

Not quite sure I understand the question. Could you give an example of the route (and perhaps a quick mockup of what it might return) that you have in mind?

@adelevie
Copy link
Contributor

To achieve a "a new API endpoint to hit and get all available data_sources":

api/app.js (approximately):

app.get('/v0/data_sources', function(req, res) {
  res.json({
    results: [
       'fbo.gov', 'grants.gov', 'dodsbir.net', 'bids.state.gov'
    ]
  });
});

Is this fine? or is there a dynamic way to populate the results array?

@arowla
Copy link
Contributor Author

arowla commented Jul 30, 2014

Gotcha. These should be dynamically populated. See the Elasticsearch sample aggregation code at the top of the Issue.

Also we may want to name the route a bit differently, but I will need to think on it and we should discuss with the group.

@adelevie
Copy link
Contributor

Great, very clarifying. Is there any code we have that already does something similar? I'm guessing that the aggregation code gets passed to (es) client.search()? (still getting used to ES w/ Node)

@arowla
Copy link
Contributor Author

arowla commented Jul 30, 2014

Yes, JSON can be passed directly to client.search({body: [insert query here]}), but since we're using Elastic.js (API docs) as a DSL to help build up queries elsewhere in the API, you should first look into whether that can do what we need without too much trouble, before resorting to raw JSON.

@adelevie
Copy link
Contributor

Looks like this is the answer. * studies docs * ...

@adelevie
Copy link
Contributor

So far

app.get('/v0/data_sources', function(req, res) {
  client.search({
    index: config.elasticsearch.index,
    type: 'opp',
    body: ejs.TermsAggregation({name: 'data_source'})
  }, function(err, body) {
    res.json(body)
  });
});

outputs:

{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[zTzPNIcxTuSlaiGgZ2ncmg][fbopen0][0]: RemoteTransportException[[Nebulos][inet[/172.23.198.98:9300]][search/phase/query]]; nested: SearchParseException[[fbopen0][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"[object Object]":{"terms":{}}}]]]; nested: SearchParseException[[fbopen0][0]: from[-1],size[-1]: Parse Failure [No parser for element [[object Object]]]]; }{[d56lqUq7S56wszWZiDuyYw][fbopen0][1]: SearchParseException[[fbopen0][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"[object Object]":{"terms":{}}}]]]; nested: SearchParseException[[fbopen0][1]: from[-1],size[-1]: Parse Failure [No parser for element [[object Object]]]]; }{[d56lqUq7S56wszWZiDuyYw][fbopen0][4]: SearchParseException[[fbopen0][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"[object Object]":{"terms":{}}}]]]; nested: SearchParseException[[fbopen0][4]: from[-1],size[-1]: Parse Failure [No parser for element [[object Object]]]]; }{[zTzPNIcxTuSlaiGgZ2ncmg][fbopen0][2]: RemoteTransportException[[Nebulos][inet[/172.23.198.98:9300]][search/phase/query]]; nested: SearchParseException[[fbopen0][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"[object Object]":{"terms":{}}}]]]; nested: SearchParseException[[fbopen0][2]: from[-1],size[-1]: Parse Failure [No parser for element [[object Object]]]]; }{[zTzPNIcxTuSlaiGgZ2ncmg][fbopen0][3]: RemoteTransportException[[Nebulos][inet[/172.23.198.98:9300]][search/phase/query]]; nested: SearchParseException[[fbopen0][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"[object Object]":{"terms":{}}}]]]; nested: SearchParseException[[fbopen0][3]: from[-1],size[-1]: Parse Failure [No parser for element [[object Object]]]]; }]","status":400}

@adelevie
Copy link
Contributor

#151 implements the data_source option

arowla added a commit that referenced this issue Aug 22, 2014
Issue #57: Add /agg endpoints to show unique data_sources, notice_types, and notice_types by data_source.
@arowla arowla closed this as completed Aug 22, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants