9

Coming from here i'm asking myselve for the elasticsearch syntax for such querys:

WHERE text LIKE "%quick%"
  AND text LIKE "%brown%"
  AND text LIKE "%fox%" 

my try (unfortunately without success)

  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "text": [
                    "*quick*",
                    "*brown*",
                    "*fox*"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
Toshi
  • 2,532
  • 4
  • 17
  • 45
  • You can use regexp. https://stackoverflow.com/questions/6467067/how-to-search-for-a-part-of-a-word-with-elasticsearch/51843146#51843146 It has worked for me. – Ali Moshiri Aug 16 '18 at 06:37
  • You can use [regexp](https://stackoverflow.com/questions/6467067/how-to-search-for-a-part-of-a-word-with-elasticsearch/51843146#51843146). It has worked for me . Good Luck. – Ali Moshiri Aug 16 '18 at 06:38

2 Answers2

14

Try using bool and wildcard to do such a query.

{
    "query": {
        "bool": {
            "must": [
                {
                    "wildcard": {
                        "text": "*quick*"
                    }
                },
                {
                    "wildcard": {
                        "text": "*brown*"
                    }
                },
                {
                    "wildcard": {
                        "text": "*fox*"
                    }
                }
            ]
        }
    }
}

Wildcard Query Matches documents that have fields matching a wildcard expression (not analyzed). Supported wildcards are *, which matches any character sequence (including the empty one), and ?, which matches any single character.

kgf3JfUtW
  • 13,702
  • 10
  • 57
  • 80
1

That's what you're looking for. Just put desired amount of wildcard queries in your bool/must:

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "text": {
              "value": "*quick*"
            }
          }
        },
        {
          "wildcard": {
            "text": {
              "value": "*brown*"
            }
          }
        },
        {
          "wildcard": {
            "text": {
              "value": "*fox*"
            }
          }
        }
      ]
    }
  }
}
Evaldas Buinauskas
  • 13,739
  • 11
  • 55
  • 107