Query & filter return no result


(Frederic Laurent) #1

Hello all,

I'm trying to make requests (very simples) on a very small dataset : 4 documents available here
https://gist.github.com/flrt/a9f29c838bfa06a2faa5#file-create-es-units-testplan-sh

What I want (for the beginning) :

  • unclosed units with title or name contains CARDIO

The idea is

  • to filter the unclosed units
  • query the fields in order to have a score (otherwise by default a filter can be used)

The mapping is the following

curl -XGET http://localhost:9200/units/_mapping
{
    "units":
    {
        "mappings":
        {
            "unit":
            {
                "properties":
                {
                    "closed":
                    {
                        "type": "date",
                        "format": "dateOptionalTime"
                    },
                    "code":
                    {
                        "type": "string"
                    },
                    "title":
                    {
                        "type": "string"
                    },
                    "user":
                    {
                        "properties":
                        {
                            "name":
                            {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }
}

My (broken) tests

Test 1/ Trying to follow https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html

I added the "query" key in the first place. Without, like in the docs, when I'm starting the json with filetered, I have the following exception

SearchParseException[[units][4]: from[-1],size[-1]: Parse Failure [No parser for element [filtered]]]; }]",

curl -XGET http://localhost:9200/units/unit/_search -d'{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "CARDIO"
        }
      },
      "filter": {
        "bool": {
          "must_not": {
            "exists": {
              "field": "closed"
            }
          }
        }
      }
    }
  }
}'

--> 0 results

Test 2/ Trying to follow https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html

curl -XGET http://localhost:9200/units/unit/_search -d'{
  "query": {
    "filtered": {
      "query": {
        "match": {
          "title": "CARDIO"
        }
      },
      "filter": {
        "bool": {
          "must_not": {
            "exists": {
              "field": "closed"
            }
          }
        }
      }
    }
  }
}'

--> 0 results

Test 3/ Trying to follow https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

curl -XGET http://localhost:9200/units/unit/_search -d'{
  "multi_match": {
    "query": "CARDIO",
    "fields": [
      "title^2",
      "user.name"
    ]
  }
}

--> Execption SearchParseException[units: from[-1],size[-1]: Parse Failure [No parser for element [multi_match]]]; }]

Test 4 / trying to mix multi_match and filter

curl -XGET http://localhost:9200/units/unit/_search -d'{
  "query": {
    "filtered": {
      "query": {
        "multi_match": {
          "query": "CARDIO",
          "fields": [
            "title^2",
            "user.name"
          ]
        }
      },
      "filter": {
        "bool": {
          "must_not": {
            "exists": {
              "field": "closed"
            }
          }
        }
      }
    }
  }
}

--> 0 results

But I have got a good result when I'm searching the unclosed units

curl -XGET http://localhost:9200/units/unit/_search -d'{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must_not": {
            "exists": {
              "field": "closed"
            }
          }
        }
      }
    }
  }
}

--> 3 results

I tried to put CARDIO and CARDIO*, but it's the same result.
I think these tests are very simples and I can't figure out why they fails.

Any idea ?


(Frederic Laurent) #2

Hello

In fact, I would like to produce the intersection between

The first one gives 3 results, and the second one gives 2. Only one is in common.

But I can't set these 2 conditions in the query string when using the URI search, and the json expression does not return anything, as explained at the beginning of these post.

Thanks in advance


(system) #3