ruby-on-railselasticsearchfull-text-searchelasticsearch-rails

Elasticsearch match field=value (not contains)


I have problem while searching through elasticsearch. I have index product with fields title and gender

When I make query with default_field: title I need to get results only with gender=male (not female or others)

query: dress AND gender:male

Results contain both genders: male and female and male,female

It seems to me that gender:* search all which contains male, but not full match of value. How to do the query right?

I use it through Ruby on Rails

Product.search({
      query: {
        query_string: {
            query: query,
            default_field: "title"
          }
        },
        size: per_page,
        sort: [ _score: { order: relevance } ]
    })

Solution

  • According with this I just need to put value in double quotes..

    query = '(dress) AND (gender:"male")'

    do not forget to escape them if needed "gender:\"male\""