0

i need to change the field dynamically

   this.search = function(search, match) {
          var deferred = $q.defer()
          search({
            size: 10000,
            index: "products",
            body: {
              "query": {
                "match": {
                  [search]: {
                    "query": match,
                    // "operator": "and",
                    type:"phrase"
                  }
                }
              }
            }

but its showing the error 30:16 error Parsing error: Unexpected token [

2
  • What browser & version are you running this in? Commented Nov 8, 2017 at 23:54
  • The name search is overloaded. It is used both as the name of a function and also as a parameter of a function. Commented Nov 9, 2017 at 18:18

2 Answers 2

1

You'll have to split it up so you can build the body object dynamically:

var body = {
    "query": {
        "match": { }
    }
};
body.query.match[search] = {
    "query": match,
    "type": "phrase"
};
Sign up to request clarification or add additional context in comments.

2 Comments

in elastic search this is not possible
It won't let you pass body as a pre-defined object? Seriously? That is messed up.
0

This isn't an AngularJS problem - the problem is you are trying to use a Computed Property Name for the object literal when the browser you are using doesn't support it.

Computed Property Name documentation link:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names

To see the which browsers can & can't use Computed Property Names:

https://kangax.github.io/compat-table/es6/#test-object_literal_extensions_computed_properties

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.