Monday, January 15, 2018

Create an alias to query elasticsearch table from express

Leave a Comment

I am querying elastic search with the values places.name and places.state via a GET in the URL. The URL looks like this… localhost:9000/search?type=location&contains%5Bplaces.name%5D=Burlington&contains%5Bplaces.state%5D=NJ

My function in express is this...

function getPlaces(index, query, options, searchFn) {   var opts = options || {};   var body = {};   body.query = {};   body.query.bool = {};   body.query.bool.must = [{     multi_match: {       query: query,       fields: [“places.name”, “places.state "]     }   }]; 

What I want to do is create additional alias fields that will still perfom a search on it’s intended table. So adding static.places.name & static.places.state would show results for places.name & places.state

I added this to fields but that didn’t work, I kind of expected that.

fields: [      "places.name”, “static.places.name”, “places.state”, “static.places.state" ] 

So localhost:9000/search?type=location&contains%5Bplaces.name%5D=Burlington&contains%5Bplaces.state%5D=NJ and localhost:9000/search?type=location&contains%5Bstatic.places.name%5D=Burlington&contains%5Bstatic.places.state%5D=NJ would show the same results.

Can I create an alias to query elasticsearch table from express? Does this make sense? Am I going about this the wrong way?

Thank in advance for your help.

1 Answers

Answers 1

Field aliases are not a supported feature in Elasticsearch, though it has been suggested (and rejected) a number of times in the Github Issues.

You'll need to make the transformation on the client-side after retrieving the result.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment