-1

I'm implement query in Elastic4s library. But I don't know how to implement a following Json query for Elasticsearch.

 {
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        {
          "keywordQuery": "hogehoge"
        }
      ]
    }
 }

I don't know how to implement this part of Json query.

{
  "keywordQuery": "hogehoge"
}

This is a code I implemented halfway.

boolQuery().must(Seq(matchAllQuery(), query("{keywordQuery: hogehoge}")))

and this is an output of an above code.

{
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        { "queryString": {
            "query": "{keywordQuery": "hogehoge}"
          }
        }
      ]
    }
 }

I expect

{
  "keywordQuery": "hogehoge"
}

but actually

{ "queryString": {
  "query": "{keywordQuery": "hogehoge}"
  }
}

Would you help me please?

1 Answers1

0

I can't find a reference to keywordQuery in the ElasticSearch DSL documentation at https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl.html or https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl.html - maybe you need a Term query?

(on e.g. Logstash indices 'text' fields have a non-analysed subfield called '.keyword' so if I do a "keyword query" I normally do termQuery("field.keyword","value))

I don't think you need to include matchAllQuery() as it's kinda implied that you start off with the full set of results, so you could drop the bool and simplify the query to:

{
  "query": {
    "term": {
      "field.keyword": "value"
    }
  }
}

In Elastic4s this would be:

client.execute {
   termQuery("field.keyword", "value")
}
fredex42
  • 90
  • 7