7

How complex can a query be on an integer array data type? Here is my class in python to inject data into elasticsearch:

class Paragraph(DocType):
    body = Text(analyzer="standard")
    published_from = Date()
    lines = Integer()
    n_paragraph = Integer()
    capture = Integer()

    class Meta:
        index = "my_index"

    def save(self, **kwargs):
        self.lines = len(self.body.split())
        return super(Paragraph, self).save(**kwargs)

I am injecting an array of integer in capture. Here is the interesting line :

paragraph.capture = [1, 0, 5, 7]
  1. I manage to query if a number is in the list:: cnx = Search().using(client) s = cnx.query("match", capture=5)

  2. as @Val said we can add another field that contains sum to query the sum

How to query a specific index e.g. paragraph.capture[1] >= 1 ?

we saw that Elasticsearch query on array index is related but I could not make the link.

1 Answer 1

1

The best way to query the sum is to add another field that contains it so you don't have to run a costly script query at search time.

Querying if at least one number is superior to 4 can already be done with a normal range query on the capture field.

Sign up to request clarification or add additional context in comments.

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.