-4

I'm building an Elasticsearch search interface. My method is to build the initial query object, and then alter it depending on the user input.

In the filter part of my object, I have

'filter':{  
    'and':[
        {
            'term' : {
                'terms.region.slug' : 'texas'
            }
        },
        {
        ...
        },
    ]
}

before I try to alter it, I at least see if I can access it.

console.log( filter.and[0].term.terms.region.slug );

However, I get:

Uncaught TypeError: Cannot read property 'region' of undefined

Maybe because the interpreter is expecting the dot notation to point to levels of an object, whereas this portion of the json going to ES is...erm.. not an object (although it's referencing an object?) This is where I get confused.

EDIT: For reference, this is what the terms object for a single result looks like in Elasticsearch.

enter image description here

psorensen
  • 809
  • 4
  • 17
  • 33

1 Answers1

2

This is because the binding you've used (i.e., 'terms.region.slug') is incompatible with dot-notation. Use of dot-notation requires that the binding be parseable as an identifier. However, bracket notation is equivalent to dot-notation and allows any binding to be used.

console.log( filter.and[0].term['terms.region.slug'] );

jamesblacklock
  • 849
  • 8
  • 14