0

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 } ]
    })

2 Answers2

0

Is gender a keyword data type? I suspect that you left/set the default mapping to the gender field (i.e., text + keyword subfield). In this case, try the following query: dress AND gender.keyword:male

glenacota
  • 2,314
  • 1
  • 11
  • 18
0

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\""